I m drawing rectangle on mouse move in c#,
i wrote the code like this,
onmousemove:
Rectangle rect = new Rectangle(
Math.Min(mouseMovePoint.X, mouseDownPoint.X),
Math.Min(mouseMovePoint.Y, mouseDownPoint.Y),
Math.Abs(mouseMovePoint.X - mouseDownPoint.X),
Math.Abs(mouseMovePoint.Y - mouseDownPoint.Y)
);
graphics.DrawRectangle(myPen, rect);
onmouseup:
this.Refresh();
Rectangle rect = new Rectangle(
Math.Min(mouseMovePoint.X, mouseDownPoint.X),
Math.Min(mouseMovePoint.Y, mouseDownPoint.Y),
Math.Abs(mouseMovePoint.X - mouseDownPoint.X),
Math.Abs(mouseMovePoint.Y - mouseDownPoint.Y)
);
graphics.DrawRectangle(myPen, rect);
But due to this refresh method when i draw the rectangle it appears like as if it s flickering how to avoid that?
Use
ControlPaint.DrawReversibleFramefor drawing selection boxes, in conjunction withMouseDown,MouseMoveandMouseUpevents. Check this on MSDN.