Moving a picture with mouse

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

    #1

    Moving a picture with mouse

    Hey...........i s it possible to move a picture around the form with the
    mouse ?

    I have a form with one picture on it........when I hold down the mouse I
    would like the picture to follow the mouse until mouse is released and then
    place the picture there.........c an anyone tell me how with a short code
    example ??




  • Auric__

    #2
    Re: Moving a picture with mouse

    "...And the next sign of the Apocalypse will be..."
    *****
    On Thu, 12 Feb 2004 08:33:02 +0100, Steen Gellett wrote:
    [color=blue]
    >Hey........... is it possible to move a picture around the form with the
    >mouse ?
    >
    >I have a form with one picture on it........when I hold down the mouse I
    >would like the picture to follow the mouse until mouse is released and then
    >place the picture there.........c an anyone tell me how with a short code
    >example ??[/color]

    With this, the picture's top left corner jumps to the cursor as soon as
    you move it - easily fixed if you have reason to. This *should* work
    with almost any control that is visible at runtime - I tested it with a
    Picture, a Label, and a CommandButton.

    Dim moveMe As Boolean

    Private Sub Pic1_MouseDown( Button As Integer, Shift As Integer, _
    X As Single, Y As Single)
    moveMe = True
    End Sub

    Private Sub Pic1_MouseMove( Button As Integer, Shift As Integer, _
    X As Single, Y As Single)
    If moveMe Then
    Pic1.Top = Pic1.Top + Y
    Pic1.Left = Pic1.Left + X
    End If
    End Sub

    Private Sub Pic1_MouseUp(Bu tton As Integer, Shift As Integer, _
    X As Single, Y As Single)
    moveMe = False
    End Sub

    --
    auric "underscore " "underscore " "at" hotmail "dot" com
    *****
    SCUD: Sure Could Use Directions

    Comment

    • Steen Gellett

      #3
      Re: Moving a picture with mouse


      "Auric__" <not.my.real@em ail.address> skrev i en meddelelse
      news:stcm20p5c4 hup373r37f7srpc e994u3u1u@4ax.c om...[color=blue]
      > "...And the next sign of the Apocalypse will be..."
      > *****
      > On Thu, 12 Feb 2004 08:33:02 +0100, Steen Gellett wrote:
      >[color=green]
      > >Hey........... is it possible to move a picture around the form with the
      > >mouse ?
      > >
      > >I have a form with one picture on it........when I hold down the mouse I
      > >would like the picture to follow the mouse until mouse is released and[/color][/color]
      then[color=blue][color=green]
      > >place the picture there.........c an anyone tell me how with a short code
      > >example ??[/color]
      >
      > With this, the picture's top left corner jumps to the cursor as soon as
      > you move it - easily fixed if you have reason to. This *should* work
      > with almost any control that is visible at runtime - I tested it with a
      > Picture, a Label, and a CommandButton.
      >
      > Dim moveMe As Boolean
      >
      > Private Sub Pic1_MouseDown( Button As Integer, Shift As Integer, _
      > X As Single, Y As Single)
      > moveMe = True
      > End Sub
      >
      > Private Sub Pic1_MouseMove( Button As Integer, Shift As Integer, _
      > X As Single, Y As Single)
      > If moveMe Then
      > Pic1.Top = Pic1.Top + Y
      > Pic1.Left = Pic1.Left + X
      > End If
      > End Sub
      >
      > Private Sub Pic1_MouseUp(Bu tton As Integer, Shift As Integer, _
      > X As Single, Y As Single)
      > moveMe = False
      > End Sub
      >[/color]

      as simple as it can be...........ma ny thx for this code.........yo u saved my
      day


      Comment

      • Rick Rothstein

        #4
        Re: Moving a picture with mouse

        > Hey...........i s it possible to move a picture around the form with the[color=blue]
        > mouse ?
        >
        > I have a form with one picture on it........when I hold down the mouse I
        > would like the picture to follow the mouse until mouse is released and[/color]
        then[color=blue]
        > place the picture there.........c an anyone tell me how with a short code
        > example ??[/color]

        Give the following a try. If you uncomment the commented-out code, the user
        will not be able to place the PictureBox off of the Form.

        Rick - MVP

        Private Declare Function SendMessage Lib "user32" _
        Alias "SendMessag eA" _
        (ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        lParam As Any) _
        As Long

        Private Declare Function ReleaseCapture Lib "user32" () As Long

        Private Const WM_NCLBUTTONDOW N = &HA1
        Private Const HTCAPTION = 2

        Private Sub Picture1_MouseD own(Button As Integer, _
        Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
        Call ReleaseCapture
        With Picture1
        Call SendMessage(.hW nd, WM_NCLBUTTONDOW N, _
        HTCAPTION, ByVal 0&)
        ' If .Left < 0 Then .Left = 0
        ' If .Top < 0 Then .Top = 0
        ' If .Left + .Width > Me.ScaleWidth Then
        ' .Left = Me.ScaleWidth - .Width
        ' End If
        ' If .Top + .Height > Me.ScaleHeight Then
        ' .Top = Me.ScaleHeight - .Height
        ' End If
        End With
        End If
        End Sub


        Comment

        Working...