该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
'仿微软画图里的多边形功能。
Option Explicit
Dim Cx() As Single, Cy() As Single, Drawing As Long, MouseDown As Boolean
Private Sub Form_Load()
AutoRedraw = True: ScaleMode = 3
DrawMode = 10: Drawing = -1
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If Drawing > -1 Then
Line (Cx(Drawing), Cy(Drawing))-(X, Y)
Else
ReDim Cx(0): ReDim Cy(0)
Cx(0) = X: Cy(0) = Y: Drawing = 0
End If
Drawing = Drawing + 1
ReDim Preserve Cx(Drawing): Cx(Drawing) = X
ReDim Preserve Cy(Drawing): Cy(Drawing) = Y
MouseDown = True
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Line (Cx(Drawing - 1), Cy(Drawing - 1))-(Cx(Drawing), Cy(Drawing))
Cx(Drawing) = X: Cy(Drawing) = Y
Line (Cx(Drawing - 1), Cy(Drawing - 1))-(X, Y)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Long
If Button = 1 Then
If MouseDown Then
MouseDown = False
Else
If Drawing > -1 Then '双击最大化也是双击……额
CurrentX = Cx(0): CurrentY = Cy(0): DrawMode = 13
For i = 1 To Drawing: Line -(Cx(i), Cy(i)), vbRed: Next
Line -(Cx(0), Cy(0)), vbRed
Drawing = -1: DrawMode = 10
End If
End If
End If
End Sub