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,
Printable View
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?
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?
it is possible,
in the mousemove event, chnage the left and top of the "other" form to the x and y of the mousebuttons
Ok that is was thinking too but how does i do that mouse event code?
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.
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?
Well, Told you not very sure of it, I will post back something, When I get home.:)
Ok many thanks :)
what does this have to do with a listview?Quote:
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,
OK, maybe this is what you are looking for...
Declare the following in a standard module
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).VB Code:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Public Type POINTAPI x As Long y As Long End Type
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:
Public Sub followCursor(Optional switch As Boolean = True) Static enabled As Boolean Dim cursorPos As POINTAPI Dim correctX As Single Dim correctY As Single Dim y As Single Dim x As Single enabled = switch Do While enabled = True If Me.WindowState <> vbMaximized Then Call GetCursorPos(cursorPos) 'Correct Twips correctX = cursorPos.x * Screen.TwipsPerPixelX correctY = cursorPos.y * Screen.TwipsPerPixelY 'Find center of form x = correctX - (Me.ScaleWidth / 2) y = correctY - (Me.ScaleHeight / 2) Me.Move x, y End If DoEvents Loop 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:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Static enabled As Boolean If enabled = True Then enabled = False Else enabled = True End If Call followCursor(enabled) 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:
Private Sub Form_Unload(Cancel As Integer) Call followCursor(False) 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.
Many thanks!!! i try it
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 :)
no problem dude.:D