在窗体上有好多的直线,我想用鼠标实现他的功能。
鼠标点击任意一条直线的任意部位时,被点上的直线变为红色,然后按住鼠标的左键拖动直线放在任意的位置。

解决方案 »

  1.   

    鼠标点击任意一条直线的任意部位时,被点上的直线变为红色:
    line.forecolor=vbred
    按住鼠标的左键拖动直线放在任意的位置:
    line.move
      

  2.   

    private sub line1_click()
        line1.forecolor=vbred
    end sub移动:Dim iPx As Integer, iPy As Integer, iMy As Integer
    Dim bb As Boolean       '控件拖动MouseDown/MouseUp判断
    Private Sub line1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bb = True
        iPx = X
        iPy = Y
        MousePointer = 5End SubPrivate Sub line1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If bb Then
            line1.Move stop1.Left + X - iPx, line1.Top + Y - iPy
        End If
    End SubPrivate Sub line1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bb = False
        MousePointer = 0End Sub
      

  3.   

    因为line没有事件,要想实现有点困难,还是想想用其它变通的方法吧
    例如用Frame控件,把高度设小一点,然后在Click事件中改变背景色,在MouseDown事件中移动控件
    具体的我没试,仅供参考
      

  4.   

    line没有事件。
    不太好弄。
      

  5.   

    czwwh(江·沙·月)兄弟说可行!frame1调成细线状
    Private Sub Frame1_Click()
        Frame1.BackColor = vbRed
    End Sub
      

  6.   

    czwwh(江·沙·月)兄弟说可行!frame1调成细线状
    Private Sub Frame1_Click()
        Frame1.BackColor = vbRed
    End Sub
      

  7.   

    UP楼上是个变通的方法你也可以直接在窗体上画直线么!
    建立一个数组,判断鼠标点击时选中哪条线(X,Y),再重画
    这样也可以吧!没有楼上简单~_~
      

  8.   

    private sub line1_click()
        line1.forecolor=vbred
    end sub移动:Dim iPx As Integer, iPy As Integer, iMy As Integer
    Dim bb As Boolean       '控件拖动MouseDown/MouseUp判断
    Private Sub line1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bb = True
        iPx = X
        iPy = Y
        MousePointer = 5End SubPrivate Sub line1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If bb Then
            line1.Move stop1.Left + X - iPx, line1.Top + Y - iPy
        End If
    End SubPrivate Sub line1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bb = False
        MousePointer = 0End Sub