我正在嘗試使用不工作的按鈕創建一條線。按鈕畫線vb.net不工作?
如果我使用下面的代碼,
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
它說:「‘圖形’不是'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
和幾個simular變化(許多列出),但我得到的錯誤響應alsorts。
那麼如何用e.graphics點擊一個按鈕畫一條線?