c# - How to draw line when mouse up? -
i trying set starting point when lmb down , draw line starting point current mouse position when lmb up, how mspaint it.
my problem can't seem line appear on picturebox when lmb up. can enlighten me please?
edit:sorry guys realised problem elsewhere, learned bunch of stuff in process, input.
public partial class formpaint : form { point? startpoint = point.empty; point? endpoint = point.empty; bool ismousedown = new boolean(); private void picturebox1_mousedown(object sender, mouseeventargs e) { if (control.mousebuttons == mousebuttons.left) { startpoint = e.location; ismousedown = true; } } private void picturebox1_mouseup(object sender, mouseeventargs e) { brush = new solidbrush(color); using (graphics g = graphics.fromimage(picturebox1.image)) { g.drawline(new pen(brush), startpoint.value, endpoint.value); picturebox1.invalidate(); } ismousedown = false; } private void picturebox1_mousemove(object sender, mouseeventargs e) { endpoint = e.location; } private void picturebox1_paint(object sender, painteventargs e) { using (brush = new solidbrush(color)) { e.graphics.drawline(new pen(brush, 5), startpoint.value, endpoint.value); } } }
when call invalidate
forces picture box repaint. problem though discards painted before. calls paint
on picture box.
i suggest save drawing data list , perform painting inside paint
event of picture box using saved data.
also read how draw circle , line in picturebox?
Comments
Post a Comment