I wanted to create a basic usercontrol that has a buffered graphics. But something is not right, it stops at the line Using gr As Graphics = Graphics.FromImage(m_Buffer)
I even managed to crash VS2010. That is why I suspect that I introduced some errors. I copied most parts from example code, and I guess that at least the OnPaint is never called because it was not one of the Events that I could select in the Designer.
Thank you very much for the help!
Public Class UserControl1
Private m_Buffer As Bitmap
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(m_Buffer, Point.Empty)
'MyBase.OnPaint(e)'what is this for?
End Sub
Public Sub PaintSomething()
Using gr As Graphics = Graphics.FromImage(m_Buffer)
gr.FillEllipse(New SolidBrush(Color.Blue), 0, 0, 100, 100)
End Using
Me.Invalidate()
End Sub
Public Sub New()
InitializeComponent()
Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer, True)
Me.UpdateStyles()
End Sub
Private Sub UserControl1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
m_Buffer = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
End Sub
End Class