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
当呼叫潜艇时:
DrawRectangleInt()
我收到一个错误,说我需要为"e"传递一些东西,但是呢?
谢谢。
你可以从 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