我正在尝试在按钮中使用以下代码。我想调用DrawLineFloat。我试过调用DrawLineFloat()但它没有用。我需要输入什么?()?
由于
Public Sub DrawLineFloat(ByVal e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create coordinates of points that define line.
Dim x1 As Single = 100.0F
Dim y1 As Single = 100.0F
Dim x2 As Single = 500.0F
Dim y2 As Single = 100.0F
' Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
End Sub
答案 0 :(得分:4)
我想你是在一个表单中调用它,但不是在Paint事件中。 因此,您需要创建用于绘制线条的图形
Public Sub DrawLineFloat()
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create coordinates of points that define line.
Dim x1 As Single = 100.0F
Dim y1 As Single = 100.0F
Dim x2 As Single = 500.0F
Dim y2 As Single = 100.0F
' Draw line to screen.
Dim g As Graphics = Me.CreateGraphics()
g.DrawLine(blackPen, x1, y1, x2, y2)
blackPen.Dispose()
End Sub
另请注意,Pen对象应尽快处理
答案 1 :(得分:0)
为什么不写
Public Sub DrawLine()
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create coordinates of points that define line.
Dim x1 As Single = 100.0F
Dim y1 As Single = 100.0F
Dim x2 As Single = 500.0F
Dim y2 As Single = 100.0F
' Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
End Sub
并调用
DrawLine()
答案 2 :(得分:-1)
尝试将null值(VB中的Nothning)传递给函数。
DrawLineFloat(Nothing)