how to control the paint event

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi,

I have a form with a picture box on it. I have set the picture box
background to black, and in the paint event for the picture box, I do:

Msgbox "In Paint Event"
PictureBox1.CreateGraphics.Clear(Color.Red)

When I run the form, the message "Paint Event" pops up and the background of
the picture box has changed to red, but when I click okay the background
reverts to black.
If I take the MsgBox out, the background stays black.

My understanding of the paint event is obviously incorrect. How do I go
about writing text or graphics to the picture box if it is going to
disappear all the time?

Also, if I open up a notepad window, and move the window around the form and
over the picture box, only certain parts of the picture box are actually
painted red. It differs depending upon how fast I move the notepad window.
Obviously, the picture box needs to be repainted perfectly every time. It's
really weird what appears to be happening.

Thanks in advance,

Richard
 
Richard...

You can reference PictureBox1 in the form's paint event but if you are
changing the picturebox to red in the picturebox paint event then you should
reference the graphics object passed to you e.graphics.clear(Color.Red)

At least it works for me...

Tom
 
* "Richard said:
I have a form with a picture box on it. I have set the picture box
background to black, and in the paint event for the picture box, I do:

Msgbox "In Paint Event"
PictureBox1.CreateGraphics.Clear(Color.Red)

Wny not simply use 'e.Graphics.Clear(Color.Red)', which is the preferred
way.
 
Back
Top