Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongConst WM_SYSCOMMAND = &H112 Const SC_MOVE = &HF012Private Sub dian_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then ReleaseCapture SendMessage dian.hwnd, WM_SYSCOMMAND, SC_MOVE, 0 End If 再连线 End Sub
实现了。我临时给你写了一个,在form中放一个picture1和line1,然后复制下面的代码。Option ExplicitDim posX1 As Single, posY1 As Single Dim posX2 As Single, posY2 As Single Dim posX3 As Single, posY3 As Single Dim nCount As Integer Dim boolMove As BooleanPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If nCount < 3 Then Exit Sub
If X > posX3 - 50 And X < posX3 + 50 And Y > posY3 - 50 And Y < posY3 + 50 Then boolMove = True Line1.X1 = posX2 Line1.Y1 = posY2 Line1.X2 = X Line1.Y2 = Y Line1.Visible = True End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If boolMove = True Then Line1.X1 = posX2 Line1.Y1 = posY2 Line1.X2 = X Line1.Y2 = Y End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
boolMove = False If nCount = 3 Then Line1.Visible = False posX3 = X: posY3 = Y
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongConst WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF012Private Sub dian_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage dian.hwnd, WM_SYSCOMMAND, SC_MOVE, 0
End If
再连线
End Sub
Dim posX2 As Single, posY2 As Single
Dim posX3 As Single, posY3 As Single
Dim nCount As Integer
Dim boolMove As BooleanPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If nCount < 3 Then Exit Sub
If X > posX3 - 50 And X < posX3 + 50 And Y > posY3 - 50 And Y < posY3 + 50 Then
boolMove = True
Line1.X1 = posX2
Line1.Y1 = posY2
Line1.X2 = X
Line1.Y2 = Y
Line1.Visible = True
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If boolMove = True Then
Line1.X1 = posX2
Line1.Y1 = posY2
Line1.X2 = X
Line1.Y2 = Y
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
boolMove = False
If nCount = 3 Then
Line1.Visible = False
posX3 = X: posY3 = Y
Picture1.Cls
Picture1.Circle (posX1, posY1), 50, vbBlack
Picture1.Circle (posX2, posY2), 50, vbBlack
Picture1.Circle (posX3, posY3), 50, vbBlack
Picture1.Line (posX1, posY1)-(posX2, posY2)
Picture1.Line (posX2, posY2)-(X, Y)
End If
If nCount >= 3 Then Exit Sub
nCount = nCount + 1
If nCount = 1 Then
posX1 = X: posY1 = Y
ElseIf nCount = 2 Then
posX2 = X: posY2 = Y
ElseIf nCount = 3 Then
posX3 = X: posY3 = Y
Picture1.Line (posX1, posY1)-(posX2, posY2)
Picture1.Line (posX2, posY2)-(posX3, posY3)
End If Picture1.Circle (X, Y), 50, vbBlack
End Sub
If boolMove = False Then Exit Sub