Visual Basic assignment

  • Thread starter Thread starter Kay Warner
  • Start date Start date
K

Kay Warner

I am having problems with persistant graphics, when I
reduce a form to an Icon I loose my picture.I understand
that graphics objects have no memory and you have to
place the code in the paint event of the graphics object
and place ObjectName_Paint(Nothing,Nothing)at the end of
each event.I have sucsessfully done this using a Form as
my graphics object but when I use a picturebox as my
graphics object it always disapears when reduced to an
icon can anyone help me?
 
Hello,

Kay Warner said:
I am having problems with persistant graphics, when I
reduce a form to an Icon I loose my picture.

Create a 'Bitmap' object ('Dim b As Bitmap = New Bitmap(...)'), get a
'Graphics' object ('Dim g As Graphics = Graphics.FromImage(b)') and draw the
image by using 'g.DrawImage(...)' etc. Don't forget do call the 'Graphics'
object's 'Dispose' method after finishing drawing. In the 'Paint' event
handler, you can draw the bitmap to the surface of the form.

Regards,
Herfried K. Wagner
 
Kay,
Instead of calling your Paint handler directly:
and place ObjectName_Paint(Nothing,Nothing)at the end of

You should invalidate the object, and optionally call Update. Or call
Refresh with does both Invalidate & Update.

' request that the object repaint itself
ObjectName.Invalidate()

' cause the object to repaint itself right now!
ObjectName.Update()


' request that the object repaint itself, and do it right now!
ObjectName.Refresh()

This way if you have more than one Paint event handler attached to the
object, or the object overrides the OnPaint method, the object will be
painted correctly.

Also:
and place ObjectName_Paint(Nothing,Nothing)at the end of

If you are sending Nothing as the PaintEventArgs, how is your Paint event
getting access to the correct Graphics object, I hope you are NOT calling
ObjectName.CreateGraphics in the Paint event, as the correct graphics object
is supplied to you, via the PaintEventArgs.

Also as Herfried stated if you call Control.CreateGraphics or
Graphics.FromImage be certain to call Graphics.Dispose on the object
returned otherwise you will have a Win32 resources leak. The Graphics object
passed in the PaintEventArgs will be taken care of for you.

Hope this helps
Jay
 
Back
Top