VB中怎么在Picture中鼠标点击三下连线画出三角形

2025-02-27 09:42:54
推荐回答(1个)
回答1:

Dim x1 As Integer, y1 As Integer, d As Integer
Private Sub Form_Load()
x1 = -1
y1 = -1
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub

If x1 = -1 Then
   Picture1.PSet (X, Y), vbRed
   x1 = X
   y1 = Y
   
Else
   Picture1.Line -(X, Y), vbRed
   d = d + 1
   If d < 2 Then Exit Sub
   Picture1.Line (X, Y)-(x1, y1), vbRed
   x1 = -1
   y1 = -1
   d = 0
   
End If

End Sub