Results 1 to 13 of 13

Thread: Move form on MouseDown instead of 'release'

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484

    Move form on MouseDown instead of 'release'

    Hi,
    I want to know how a form can be moved on the MouseDown event, like you can move the form while dragging it, instead of 'finish' dragging it. Just like Winamp. Pls tell me

    thanx

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Try making a boolean value (myBool), and four long values (nX, nY, cX, cY) in the General Declarations. On the MouseDown, set this boolean to true, and nX and nY values to the X and Y. Then, in the mousemove, make cX equal to nX - X, and cY equal to nY - Y. Then set nX to X, and nY to Y. On the MouseUp, set the boolean to false. Here's a bit of code explaining this:
    VB Code:
    1. [COLOR=indigo]Form1.frm[/COLOR]
    2. Option Explicit
    3. Dim myBool
    4. Dim nX As Long
    5. Dim nY As Long
    6. Dim cX As Long
    7. Dim cY As Long
    8.  
    9. Private Sub Form_MouseDown(...)
    10.    myBool = True
    11.    nX = X
    12.    nY = Y
    13. End Sub
    14.  
    15. Private Sub Form_MouseMove(...)
    16.    cX = X - nX
    17.    cY = Y - nY
    18. End Sub
    19.  
    20. Private Sub Form_MouseUp(...)
    21.    myBool = False
    22. End Sub
    After this, you can do basically whatever you want with this code, you could set the form's position, or make a selection rectangle. Lots of things can be accomplished!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484
    what does the X and Y stand for and wat ar variables like nY for?

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    If you clicked, and held and moved your mouse, nX and nY would be the amount it was moved every time. X and Y are the positions of your mouse from the top of the form [or control] and from the left of the form [or control], respectively.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484
    i get what u mean but i still can't get it to work
    poor me..

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well the code in itself does nothing! To add functionality... add Me.Move cX, cY after all the other code in the mousemove section.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484
    oh it worked(somehow).....but it turned out funny, all flickering and leaving traces until i release and move my mouse away?

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yeah, it tends to do that. There is a non-buggy windowless move somewhere on the 'net, try to find that.

    Cheers from Canada
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Sas you should know I have that demo

    However, I corrected you that code, try this:

    Code:
    'Variables
        Dim X2 As Long
        Dim Y2 As Long
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'Store mouse position
        X2 = X
        Y2 = Y
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'Move form if neccessary
        If Button = 1 Then: Me.Move Me.Left + (X - X2), Me.Top + (Y - Y2)
    End Sub
    
    'Code improved by vBulletin Tool 2.0

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    True fox, too true =)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484
    thanx and agree

  12. #12
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    hmmmm

    there is a setting in windows to change that...
    it makes the form move while you drag it...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    *sigh* thats not what he meant

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width