首先在picture1的MouseMove事件中(要判断鼠标是否被按下)取得当前鼠标的位置,并利用两不动点及当前鼠标位置画连线,最后捕捉鼠标放开时的位置,清除Picture1内的内容,重新画点!

解决方案 »

  1.   

    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
      

  2.   

    实现了。我临时给你写了一个,在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
            
            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
      

  3.   

    在 Picture1_MouseUp 模块中的第一行,再加一句:
        
        If boolMove = False Then Exit Sub
      

  4.   

    利用 控件的 Drag 方法,记录 控件起始的坐标,移动后的坐标,擦掉原来的直线,利用 line 在两点之间重新花线,就可以了,要想只沿着 Y 动作的时候,可以令 X  为一个常量啊,呵呵,msdn 上,有 鼠标动作的例子的。