【问题标题】:Trying to draw on a Picture Box, but nothing appears尝试在图片框上绘图,但没有出现
【发布时间】:2012-06-30 01:19:36
【问题描述】:

我正在将一个 VB6 应用程序转换为在图片框上绘制的 VB.Net。自然地,我阅读了精美的手册并打开了这个例子here。因此,我制作了一个仅包含图片框的表单的小项目,并尝试了以下操作:-

Private Sub Picture1_paint(ByVal sender As System.Object, _
                           ByVal e As System.EventArgs) _
            Handles PictureBox1.Paint
    Dim mygraphics As Graphics
    mygraphics = PictureBox1.CreateGraphics
    Dim pen As New Drawing.Pen(System.Drawing.Color.Red, 1)
    mygraphics.DrawEllipse(pen, 0, 0, 100, 100)
    pen.Dispose
End Sub

就像它说的那样。但是在运行应用程序时,该框变为空白。寻求帮助出现了一个建议here,我应该改用Frame,但结果是一样的。我检查了我没有在背景颜色中绘制,并且该函数实际上被调用了。

我忽略了什么?

【问题讨论】:

    标签: vb.net picturebox


    【解决方案1】:

    Paint 处理程序的 EventArgs 类型无效。应该是System.Windows.Forms.PaintEventArgs

    使用e.Graphics属性获取图形实例。

     mygraphics = e.Graphics
    

    参考链接MSDN - Control.Paint Event

    【讨论】:

      【解决方案2】:

      我认为e 属于PainEventArgs 类型,在e.Graphics 中已经包含一个图形对象。改用它。

      Public Class Form1
      
          Private Sub PictureBox1_Paint(ByVal sender As System.Object, _
                      ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
      
              Dim pen As New Pen(Color.Red, 1)
              e.Graphics.DrawEllipse(pen, 0, 0, 100, 100)
              pen.Dispose()
      
          End Sub
      
      End Class
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-20
        • 1970-01-01
        • 1970-01-01
        • 2017-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-01
        相关资源
        最近更新 更多