graphics - Draw lines on a picturebox using mouse clicks in C# -
i'm trying make program draw lines on picturebox using mouse clicks locations of line drawn , to. current code:
public partial class form1 : form { int drawshape; private point p1, p2; list<point> p1list = new list<point>(); list<point> p2list = new list<point>(); public form1() { initializecomponent(); picturebox1.image = new bitmap(picturebox1.width, picturebox1.height); } private void button1_click(object sender, eventargs e) { drawshape = 1; } private void button2_click(object sender, eventargs e) { drawshape = 2; } private void picturebox1_mousedown(object sender, mouseeventargs e) { if (drawshape == 1) { if (p1.x == 0) { p1.x = e.x; p1.y = e.y; } else { p2.x = e.x; p2.y = e.y; p1list.add(p1); p2list.add(p2); invalidate(); p1.x = 0; } } } private void picturebox1_paint(object sender, painteventargs e) { graphics g = graphics.fromimage(picturebox1.image); if (drawshape == 1) { using (var p = new pen(color.blue, 4)) { (int x = 0; x < p1list.count; x++) { g.drawline(p, p1list[x], p2list[x]); } } } }
at moment doesn't allow me draw on picturebox @ all. how possible?
change invalidate();
picturebox1.invalidate();
Comments
Post a Comment