0

我想创建一个具有缓冲图形的基本用户控件。但是有些不对劲,它停在 Using gr As Graphics = Graphics.FromImage(m_Buffer) 这一行

我什至设法使 VS2010 崩溃。这就是为什么我怀疑我引入了一些错误。我从示例代码中复制了大部分部分,我猜至少 OnPaint 从未被调用,因为它不是我可以在设计器中选择的事件之一。

非常感谢你的帮助!

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

结束类

4

0 回答 0