I tried implementing double buffering on a single control without success.
Any idea what im missing here? The datagrid no longer paints at all, its
just a black box.
The form event
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If m_buffer Is Nothing Then
m_buffer = New Bitmap(Me.Clien tSize.Width, Me.ClientSize.H eight)
dg.Buffer = m_buffer
End If
Dim g As Graphics = Graphics.FromIm age(m_buffer)
g.Clear(SystemC olors.Control)
g.Dispose()
'Copy the back buffer to the screen
e.Graphics.Draw ImageUnscaled(m _buffer, 0, 0)
End Sub
Protected Overrides Sub OnPaintBackgrou nd(ByVal pevent As
PaintEventArgs)
'Don't allow the background to paint
End Sub
Protected Overrides Sub OnSizeChanged(B yVal e As EventArgs)
If Not (m_buffer Is Nothing) Then
m_buffer.Dispos e()
m_buffer = Nothing
End If
MyBase.OnSizeCh anged(e)
End Sub
The derived class
Public Class BufferedDataGri d
Inherits DataGrid
Private m_buffer As Bitmap
Public Property Buffer() As Bitmap
Get
Return m_buffer
End Get
Set(ByVal Value As Bitmap)
m_buffer = Value
End Set
End Property
Public Sub New()
SetStyle(Contro lStyles.AllPain tingInWmPaint Or
ControlStyles.U serPaint Or ControlStyles.D oubleBuffer, True)
End Sub
Protected Overrides Sub OnPaint(ByVal pe As
System.Windows. Forms.PaintEven tArgs)
If m_buffer Is Nothing Then Return
Dim peArgs As New PaintEventArgs( Graphics.FromIm age(m_buffer),
pe.ClipRectangl e)
MyBase.OnPaint( peArgs)
End Sub
End Class
"Jamin Guy" <ja******@gmail .com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
http://www.bobpowell.net/doublebuffer.htm
Double buffering will only affect the Form.OnPaint method, which you
will have to override if you use the techniques described in the link
above. The controls on your form all have their own OnPaint methods,
which have nothing to do with the form's double buffering. You would
have to implement double buffering on each individual control...