好的,这段代码之前运行良好,您可以测试它以供学习
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'dimension variables of local scope
Dim myGraphics As Graphics
Dim myRectangle As Rectangle
Dim myPen As New Pen(Color.Blue)
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(ActiveForm().Handle)
'create a rectangle based on x,y coordinates, width, & height
myRectangle = New Rectangle(x:=5, y:=5, Width:=10, Height:=40)
'draw rectangle from pen and rectangle objects
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
'create a rectangle based on Point and Size objects
myRectangle = New Rectangle(Location:=New Point(10, 10), Size:=New Size(Width:=20, Height:=60))
'draw another rectangle from Pen and new Rectangle object
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
'draw a rectangle from a Pen object, a rectangle's x & y,
' width, & height
myGraphics.DrawRectangle(pen:=myPen, x:=20, y:=20, Width:=30, Height:=80)
End Sub