drawing on a picturebox...and keeping it drawn

  • Thread starter Thread starter Jim Bancroft
  • Start date Start date
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!
 
Thanks, Kevin. Should I put the code below in the OnPaint method itself, or
is there another technique I should follow?
 
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.
 
Back
Top