http://www.codeproject.com/vb/net/graphicsdoublebuffer.asp#xxxx
Introduction
This is a simple class i designed to remove flickering from painting controls with gdi . The class removes flickering by double buffering the drawing. It draws on a separate bitmap canvas file. Once all drawing is complete, you can then push the drawing to the main Drawing Canvas All at Once. This Will Kill Most IF NOT All Flickering The Drawing Products.
Code
Below Is The Simple Class:
Public Class GraphicsdoubleBuffer
Private p_canvas as bitmap
Public property [canvas] () AS Bitmap
Get
Return P_canvas
END GET
Set (ByVal Value As Bitmap)
P_canvas = value
End set
End Property
Public Sub New (Byval Canvaswidth As INTEGER,
Byval canvasheight as integer
P_canvas = new bitmap (canvaswidth, canvasheight)
End Sub
Public Function Store () AS Graphics
DIM G as graphics = graphics.fromimage (p_canvas)
Return G
END FUNCTION
Public Sub Paint (Byval WHERE As Object)
Dimg as graphics = where.creategraphics ()
g.smoothingmode = smoothingmode.none
DIM G2 AS Graphics = graphics.fromimage (p_canvas)
g2.smoothingmode = smoothingmode.none
g.drawImage (p_canvas, 0, 0)
g.dispose ()
g2.dispose ()
End Sub
Public Sub [Dispose] ()
P_canvas.dispose ()
End Sub
End Classto Use this class in your custom control address.
Dimg (ClientRectangle.width,
ClientRectangle.height)
g.store ()
g.paint (me)
g.dispose ()
START by declaring a constructor to the
Graphicsdoublebuffer () Class. Pass the the constructor the Drawing Dimensions of Your Canvas Or Form. Next USE
Store () as Your New
GDI GRAPHICS Object. You can do this several ways.
EXAMPLE 1:
Dim g2 as graphics = g.Store () g2.FillRectangle (New Solidbrush (Color.Black), New Rectangle (20, 20, 20, 20))
EXAMPLE 2:
G.Store.FillRectangle (New Solidbrush (Color.Black),
New Rectangle (20, 20, 20, 20)) After you have Drawn to the
Store () Graphics Object, You1n Must Push It To your main drawing canvas like SO:
g.paint (me)
"ME" Must Be The User Control or Form. After That We dispose () of The Drawing Object To Clear IT from Memory.
g.dispose ()
Resources
http://windowsforms.net/articles/windowsformspainting.aspx
Conclusionwell this contrudes my Simple Double Buffering Class. If You Use this class properties to you. Latez, VectorX
About Vectorx
Currently I am building my new Website http://www.codevendor.com. All Updates to my code tutorials will be listed there.if you need to talk to me in person You can chat with me on efnet Irc in the #ASP, # asp.net or #mscolib channels.latez, VectorX Click Here To View VectorX's Online Profile.