|
-
Sep 4th, 2002, 06:35 AM
#1
Thread Starter
Hyperactive Member
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,
-
Sep 4th, 2002, 06:53 AM
#2
PowerPoster
-
Sep 4th, 2002, 06:55 AM
#3
Thread Starter
Hyperactive Member
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?
-
Sep 4th, 2002, 06:59 AM
#4
PowerPoster
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
-
Sep 4th, 2002, 07:07 AM
#5
Thread Starter
Hyperactive Member
Ok that is was thinking too but how does i do that mouse event code?
-
Sep 4th, 2002, 07:17 AM
#6
PowerPoster
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.
-
Sep 4th, 2002, 07:22 AM
#7
Thread Starter
Hyperactive Member
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?
-
Sep 4th, 2002, 07:25 AM
#8
PowerPoster
Well, Told you not very sure of it, I will post back something, When I get home.
-
Sep 4th, 2002, 07:27 AM
#9
Thread Starter
Hyperactive Member
Ok many thanks
-
Sep 4th, 2002, 08:40 PM
#10
The picture isn't missing
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  .
-
Sep 5th, 2002, 03:33 AM
#11
New Member
OK, maybe this is what you are looking for...
Declare the following in a standard module
VB Code:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
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:
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.
-
Sep 5th, 2002, 04:02 AM
#12
Thread Starter
Hyperactive Member
-
Sep 5th, 2002, 04:08 AM
#13
Thread Starter
Hyperactive Member
-
Sep 5th, 2002, 04:09 AM
#14
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|