double buffering

G

Guest

Hello,
I have a windows application written in vb.net that involves a
treecontrol on the
left triggering the loading of forms on the right of the screen. However
there is a lot of flickering of the forms when loading. The code I have
attached deals
with a lot of the building of controls, however how do I stop the background
from
re-painting itself on loading. I am using the Office 2003 styles and when I
load my
forms you can distinctly see the forms changing colour from grey to blue,
which is
annoying for the users. Is there anyway of stopping the background colour
from
displaying until it is fully formed and so there will be less flickering.

Thanx in advance
Robert




Private _backBuffer As Bitmap





Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

If _backBuffer Is Nothing Then

_backBuffer = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)

End If



Dim g As Graphics = Graphics.FromImage(_backBuffer)



'Paint on the Graphics object here



g.Dispose()



'Copy the back buffer to the screen

e.Graphics.DrawImageUnscaled(_backBuffer, 0, 0)

End Sub 'OnPaint



'base.OnPaint (e); //optional but not recommended



Protected Overrides Sub OnPaintBackground(ByVal pevent As
PaintEventArgs)
End Sub 'OnPaintBackground



'Don't allow the background to paint



Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)

If Not (_backBuffer Is Nothing) Then

_backBuffer.Dispose()

_backBuffer = Nothing

End If

MyBase.OnSizeChanged(e)

End Sub 'OnSizeChanged
 
G

Guest

You may want to look at the BeginUpdate and EndUpdate methods on the TreeView
class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top