Keeping Graphics on the form

Pirahnaplant

Well-known member
Joined
Mar 29, 2009
Messages
75
Programming Experience
3-5
I am using the following method to draw graphics onto a form.
VB.NET:
Dim palette As Graphics = Me.CreateGraphics
palette.DrawImage(image, x, y)
The problem is that whenever the form is minimized or resized etc. the drawings disappear. How can I stop this from happening?
 
You're supposed to do all your GDI+ drawing on the Paint event, so that every time the form gets repainted your drawing gets redone. If you want to change what's being drawn you simply change the variables that control the drawing and then force a repaint. All the old drawing disappears and the new drawing gets done.
 
As in........
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
'Do you drawing inside here.
e.Graphics.DrawImage(Image, x, y)
End Sub
 
Back
Top