Public Sub DrawRectangleInt(e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create location and size of rectangle.
Dim x As Integer = 0
Dim y As Integer = 0
Dim width As Integer = 200
Dim height As Integer = 200
' Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, x, y, width, height)
End Sub
用以下方式调用Sub时
DrawRectangleInt()
我得到一个错误,说我需要为'e'传递一些东西,但是什么?
感谢。
答案 0 :(得分:2)
您可以从paint事件中调用该sub并将e
变量传递给您的sub,或者在您的sub中创建Graphics对象。使用/结束使用块正确处理对象。
Public Sub DrawRectangleInt()
' Create pen.
Using blackPen As New Pen(Color.Black, 3)
' Create location and size of rectangle.
Dim x As Integer = 0
Dim y As Integer = 0
Dim width As Integer = 200
Dim height As Integer = 200
' Draw rectangle to screen.
Using g As Graphics = Me.CreateGraphics
g.DrawRectangle(blackPen, x, y, width, height)
End Using
End Using
End Sub