I am not quite sure how to draw a Rectangle (not filled) when I drag my mousedown while left clicking the mouse.
I have this so far
private void canevas_MouseDown( object sender , MouseEventArgs e )
{
if( e.Button == MouseButtons.Left )
{
_topLeft = new Point( e.X , e.Y );
_drawing = true;
}
}
private void canevas_MouseMove( object sender , MouseEventArgs e )
{
if( _drawing )
{
Rectangle rec = new Rectangle( _topLeft.X , _topLeft.Y , ( e.X - _topLeft.X ) , ( e.Y - _topLeft.Y ) );
canevas.CreateGraphics().DrawRectangle( Pens.Black , rec );
}
}
But the problems it that I dont want all the rectangles to show up
Best Answer
Some code to go with Ed's correct answer:
To get a 'canevas' that has double-buffering turned on, so it painting doesn't flicker, use Project + Add New Item, select "Class" and paste this code:
Compile. Drag the new control from the top of the toolbox onto your form, replacing the original 'canevas'. Update the event handlers accordingly.