Mouse position?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Smiley

    Mouse position?

    I want one end of a line to follow the mouse?


  • Rick Rothstein

    #2
    Re: Mouse position?

    > I want one end of a line to follow the mouse?

    Start a new project and put a Line control on the Form. Set the AutoDraw
    property of the Form to True and the Visible property of the Line control to
    False. Paste the following code into the Form's code window. Run the
    program. Click and Drag a line with the mouse button down. When you release
    the mouse button, the Line will "stick" and you can then draw a new line
    anywhere else that you want.

    Rick - MVP

    Dim Drawing As Boolean

    Private Sub Form_MouseDown( Button As Integer, Shift As Integer, X As Single,
    Y As Single)
    With Line1
    .Visible = True
    .X1 = X
    .Y1 = Y
    .X2 = X
    .Y2 = Y
    Drawing = True
    End With
    End Sub

    Private Sub Form_MouseMove( Button As Integer, Shift As Integer, X As Single,
    Y As Single)
    If Drawing Then
    With Line1
    .X2 = X
    .Y2 = Y
    End With
    End If

    End Sub

    Private Sub Form_MouseUp(Bu tton As Integer, Shift As Integer, X As Single, Y
    As Single)
    Drawing = False
    With Line1
    Me.Line (.X1, .Y1)-(.X2, .Y2)
    .Visible = False
    End With
    End Sub


    Comment

    • CajunCoiler \(http://www.cajuncoiler.tk\)

      #3
      Re: Mouse position?


      "Smiley" <[email protected] > wrote in message
      news:ao0jb.1335 24$Of2.3984171@ twister.tampaba y.rr.com...[color=blue]
      > I want one end of a line to follow the mouse?[/color]

      Get your mouse position like this...

      Private Sub Form_MouseMove( Button As Integer, Shift As Integer, X As Single,
      Y As Single)
      ' X= horizontal mouse position
      ' Y=vertical mouse position
      End Sub

      I'm sure you can figure out how to draw a line
      from StartX,StartY to X,Y right?


      Comment

      Working...