Results 1 to 14 of 14

Thread: Another listview question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259

    Another listview question

    What i need to do is drag a form on the same "top" of a record. Actually the same height of the mouse cursos at that moment. Is that possible to do?

    best regards,

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    ?

    What?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259
    Ok i try to tell it different. I have a form and i wish that the form follow the position of the mouse cursor. Is that possible?

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    yes

    it is possible,

    in the mousemove event, chnage the left and top of the "other" form to the x and y of the mousebuttons

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259
    Ok that is was thinking too but how does i do that mouse event code?

  6. #6
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    hi

    I dont have Vb here, or I would have posted something for you.

    See the events of the control you want to display the "other " form on....prpobably it will have a mousemove event or a mouse over event.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259
    Ok i have found it but the x and y position is not the same as the position of the form. maybee the x and y aren't the pixel positions? :s?

  8. #8
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Well, Told you not very sure of it, I will post back something, When I get home.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259
    Ok many thanks

  10. #10
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217

    Re: Another listview question

    Originally posted by Matrixxx
    What i need to do is drag a form on the same "top" of a record. Actually the same height of the mouse cursos at that moment. Is that possible to do?

    best regards,
    what does this have to do with a listview?
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  11. #11
    New Member
    Join Date
    May 2001
    Location
    The Rock
    Posts
    13
    OK, maybe this is what you are looking for...
    Declare the following in a standard module
    VB Code:
    1. Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    2. Public Type POINTAPI
    3.         x As Long
    4.         y As Long
    5. End Type
    This is an API that you can use to find the position of the cursor on the screen (the x and y that you get from a mousemove event are the x and y on the current form, and so are not overly useful here).

    Then put the following code in your form. This is the code that causes your mouse to follow the cursor. Static enabled As Boolean gives us a variable whose state won't change between calls to this function. This allows us to keep track of whether the following cursor thing is switched on or off (If it were always on, you wouldn't be able to do anything else in your application).

    First, we only loop when enabled is true. Then we check if the form is maximised (you can't move a form that's maximised - you get an error). If its not then we carry on. GetCursorPos is called to get the current position of the cursor. The two lines below the comments "'Correct Twips" ensure that the proper x and y positions are used. This assumes that the scalemode of your form is vbTwips (the default). If you change your scalemode, you will have to write code to convert the measurements here.
    After this, we find the center of the form which means that the center of the form follows the mouse around (just try replacing those lines with "x = correctX" and "y = correctY" to see why this is. We then move the form. This is the fast way of saying "me.left = x" and "me.top = y". Finally we have a doEvents. This allows the form to be repainted in its new position, and also allows the user to do other things, like close the form.

    VB Code:
    1. Public Sub followCursor(Optional switch As Boolean = True)
    2.  
    3.     Static enabled As Boolean
    4.     Dim cursorPos As POINTAPI
    5.     Dim correctX As Single
    6.     Dim correctY As Single
    7.     Dim y As Single
    8.     Dim x As Single
    9.    
    10.     enabled = switch
    11.     Do While enabled = True
    12.         If Me.WindowState <> vbMaximized Then
    13.             Call GetCursorPos(cursorPos)
    14.            
    15.             'Correct Twips
    16.             correctX = cursorPos.x * Screen.TwipsPerPixelX
    17.             correctY = cursorPos.y * Screen.TwipsPerPixelY
    18.  
    19.            
    20.             'Find center of form
    21.             x = correctX - (Me.ScaleWidth / 2)
    22.             y = correctY - (Me.ScaleHeight / 2)
    23.            
    24.             Me.Move x, y
    25.         End If
    26.         DoEvents
    27.     Loop
    28.  
    29. End Sub

    Now, the following code goes in the mousedown event of the form (although it could go in any event you like, really). It simply switches the cursor following thing on/off every time you click on the form.

    VB Code:
    1. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.  
    3.     Static enabled As Boolean
    4.    
    5.     If enabled = True Then
    6.         enabled = False
    7.     Else
    8.         enabled = True
    9.     End If
    10.    
    11.     Call followCursor(enabled)
    12. End Sub

    Make sure you put the following code in the form unload event. This turns off the cursor following thing when the user closes the form. This is needed because... if the cursor thing is running when the form is unloaded, the code keeps running even though the form is not visible. It just sits on the doEvents line, waiting for something to happen! Anyway, this stops that from happening.
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     Call followCursor(False)
    3. End Sub

    To use this, run the app, and click on the form (not the title bar). Move the mouse. The center of the form will follow the mouse. Click on the form again, and the form will stay where it is. etc.

    Hope this is what you were after.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259
    Many thanks!!! i try it

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    259
    THAT IS AMAZING!!! you are the best programmer in the world . kidding,

    Many thanks,

    What i need to do is,
    I have a listview, when i klik on a record a form with soms information in must be as the same top of the index i am klicking. now it works

    best regards

  14. #14
    New Member
    Join Date
    May 2001
    Location
    The Rock
    Posts
    13
    no problem dude.

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