PersistentGraphics

From HashVB
Revision as of 09:46, 6 November 2006 by Dee (Talk | contribs)

Jump to: navigation, search
float
 This article is based on Visual Basic.NET. Find other Visual Basic.NET articles.

For those migrating from VB6 to VB.Net one noticeable change is the lack of an AutoRedraw property for Forms. If you try to draw to your form in .Net (using Me.CreateGraphics) you'll notice that your form flickers the image (or shape or text) you tried to draw and then returns to normal. In order to draw persistently you must add the following code to your form

Private Sub Form_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
        e.Graphics.DrawImage(New Bitmap(Me.Width, Me.Height, Me.CreateGraphics), 0, 0)
End Sub

Your form may still flicker if you are drawing repeatedly to your form. If this is the case, read up on back buffers.