【发布时间】:2013-04-22 20:14:52
【问题描述】:
我正在尝试使用不起作用的按钮创建一条线。
如果我使用下面的代码,
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim pn As New Pen(Color.Blue)
Dim pt1 As New Point(30, 30)
Dim pt2 As New Point(110, 100)
g.DrawLine(pn, pt1, pt2)
End sub
效果很好,但是如果我只想在单击按钮后进行绘制,例如,
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As Graphics = e.Graphics
Dim pn As New Pen(Color.Blue)
Dim pt1 As New Point(30, 30)
Dim pt2 As New Point(110, 100)
g.DrawLine(pn, pt1, pt2)
End Sub
它说“‘Graphics’不是‘System.EventArgs’的成员。???
我也尝试过改变:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
收件人:
Private Sub Button1_Click(ByVal sender As graphics.Object, ByVal e As System.EventArgs) Handles Button1.Click
还有一些类似的变化(很多都列出来了),但我得到了一些错误响应。
那么如何使用 e.graphics 通过单击按钮绘制一条线???
【问题讨论】: