By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,584 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Draw rectangle on picturebox (moving with mouse)

P: 5

I've written some code to draw a rectangle on a picture box when the user moves the mouse.
(the previous rectangle is cleared)
This works fine but the very first rectangle is not removed from the screen.

here is my code

private Rectangle r = new Rectangle(new Point(0,0), new Size(0,0));

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
Point startPoint = ((Control)sender).PointToScreen(new Point(e.X, e.Y));

ControlPaint.DrawReversibleFrame(r, this.BackColor, FrameStyle.Dashed);

r = new Rectangle(startPoint.X, startPoint.Y, 100, 200);
ControlPaint.DrawReversibleFrame(r, this.BackColor, FrameStyle.Dashed);
Feb 27 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.