You can set double buffering using the .SetStyles method for the control or
Form. Note that you need to read it carefully because using double buffering
requires the userdraw the control or form background if any and any text or
shapes on the background.
Tha basic concept I would use for your problem is to create a bitmap the
same size as your form client area. You would need to recreate this bitmap
everytime the form was resized. You can draw your backgound if you have one
on the bitmap or if the background is another bitmap, just copy that bitmap
to the bitmap you are using for the form (call it formbitmap).
You can convert the shapes into bitmaps and use bitblt to copy them to the
formbitmap at the position you want them. When they move, just recopy the
background bitmap and the shapes in their niew locations.
Use bitblt for all the copying of background bitmap and shape bitmaps to the
formbitmap and GDI for drawing text or whatever on the formbitmap. When you
are finished drawing, use the Invalidate (cliprect) to redraw the form. Note
that the cliprect is the area that you jusr redrew on the formbitmap
(probably the whole bitmap rectangle in your case).
In the Paint event (this is triggered by the .Invalidate method or a user
moving another window over the form) you can copy the formbitmap
(cliprectangle portion) to the form's graphics object which is passed as a
parameter in the Paint Event. For example (note that gph is the graphics
object for the bitmap on which you can draw text, etc. on the formbitmap.
Public Class myform
formbitmap As Bitmap = New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
dim gph as graphics = Graphics.FromImage(formbitmap)
.....
'Do your drawing on gph and use bitblt to copy background orshape bitmaps to
formbitmap
'Note: you can find lots of examples of copying a bitmap to another bitmap
on Google.
.....
.....
myform.Invalidate() 'redraws the whole form or
myform.Invalidate(cliprect) 'redraws only the rectange where changes were made
'Note that when the form is redrawn because the user popped up a message box
or somehow put another window over the form then removed it then the Paint
event will be called where the cliprect is the whole form.
'Note that if the user resizes the form, then you will have to dispose of
the current formbitmap and the graphics object the create them:
gph.Dispose:formbitmap.Dispose
formbitmap As Bitmap = New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
dim gph as graphics = Graphics.FromImage(formbitmap)
'Note: When you Close the form, then in the dispose event you need to
dispose of gph and formbitmap.
End Class
Private Sub myform_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim hdcControl As IntPtr = e.Graphics.GetHdc
Dim hdcBitmapDC As IntPtr = gph.GetHdc
Dim hdcBitmapHandle As IntPtr = formbitmap.GetHbitmap
SelectObject(hdcBitmapDC, hdcBitmapHandle)
BitBlt(hdcControl, e.ClipRectangle.X, e.ClipRectangle.Y, _
e.ClipRectangle.Width, e.ClipRectangle.Height, hdcBitmapDC,
e.ClipRectangle.X, _ e.ClipRectangle.Y, &HCC0020)
DeleteObject(hdcBitmapHandle)
gph.ReleaseHdc(hdcBitmapDC)
e.Graphics.ReleaseHdc(hdcControl)
end sub
Hope this helps. You will find that bitblt is blazing fast and I'll almost
guarantee that you won't have flicker especially if you use double buffering