drawing on a picturebox...and keeping it drawn

J

Jim Bancroft

I'm trying to draw a red rectangle over a picturebox, with some luck.
Problem is, the rectangle only flashes, then disappears, as though a repaint
keeps taking it away. Here's a code snippet from my method:

pictureBox1.CreateGraphics().FillRectangle(bsh, new Rectangle(x, y, 30,
30));
pictureBox1.Invalidate(new Rectangle(x,y,30, 30));
pictureBox1.Refresh();

I've tried various things...invalidating the entire picturebox, calling
Update() instead of Refresh...everything but the kitchen sink. I guess I
need a better grounding in what to do in situations like this. My paint()
method on the form is generic, I haven't done anything to it. Thanks for
the help!
 
J

Jim Bancroft

Thanks, Kevin. Should I put the code below in the OnPaint method itself, or
is there another technique I should follow?
 
K

Kevin Spencer

Yes, override the OnPaint method. This way, you're actually controlling the
painting of the Control, each time that it is painted.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

If the Truth hurts, wear it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top