|
-
Jan 10th, 2008, 05:37 PM
#1
Thread Starter
Lively Member
[2005] Reset Mouse Pointer Location On Hover
At runtime, if a user hovers his mouse over a specific form, i want to reset the pointer location somewhere else. Any suggestions on best way to implement this?
-
Jan 10th, 2008, 05:55 PM
#2
Re: [2005] Reset Mouse Pointer Location On Hover
you can do it using an API function
vb Code:
Public Class Form1
Private r1 As New Rectangle(10, 10, 100, 100)
Private Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Integer, ByVal y As Integer) As Integer
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim pt As New Point(e.Location.X, e.Location.Y)
If r1.Contains(pt) Then
SetCursorPos(Me.Left + e.Location.X + 100, Me.Top + e.Location.Y + 100)
End If
End Sub
end class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 10th, 2008, 06:07 PM
#3
Re: [2005] Reset Mouse Pointer Location On Hover
vb.net Code:
Private Sub Form1_MouseHover(ByVal sender As Object, _ ByVal e As EventArgs) Handles Me.MouseHover 'Move the cursor to the top left corner of 'the screen when it hovers over the form. Cursor.Position = Point.Empty End Sub
-
Jan 10th, 2008, 06:50 PM
#4
Thread Starter
Lively Member
Re: [2005] Reset Mouse Pointer Location On Hover
 Originally Posted by jmcilhinney
vb.net Code:
Private Sub Form1_MouseHover(ByVal sender As Object, _
ByVal e As EventArgs) Handles Me.MouseHover
'Move the cursor to the top left corner of
'the screen when it hovers over the form.
Cursor.Position = Point.Empty
End Sub
For some reason it is not working as anticipated. Sometimes it moves, but other times it lets me hover and even trigger the click event. I'm actually trying to prevent the click event on the specific form from occurring.
-
Jan 10th, 2008, 07:04 PM
#5
Re: [2005] Reset Mouse Pointer Location On Hover
The form will not raise a MouseHover event if you hover over a child control. Also, the MouseHover event is not raised until a hover is detected, which means that the cursor will have to have been stationary for a small period of time. That's what hovering means.
I don't quite understand all this anyway. You don't have to hover over a control to click it. You can click without the mouse cursor being stationery. Why would you want to prevent a Click event anyway? Can you please provide a proper description of what you're trying to accomplish?
-
Jan 10th, 2008, 08:30 PM
#6
Thread Starter
Lively Member
Re: [2005] Reset Mouse Pointer Location On Hover
 Originally Posted by jmcilhinney
The form will not raise a MouseHover event if you hover over a child control. Also, the MouseHover event is not raised until a hover is detected, which means that the cursor will have to have been stationary for a small period of time. That's what hovering means.
I don't quite understand all this anyway. You don't have to hover over a control to click it. You can click without the mouse cursor being stationery. Why would you want to prevent a Click event anyway? Can you please provide a proper description of what you're trying to accomplish?
You tried to help me with a bug in my program. I use two monitors. I have a form on the 2nd monitor with a TLP. The TLP refreshes data by use of a timer. For some reason, when clicked the TLP shifts. I tried your suggestion of handling the locationchanged event of the tlp but it did not help me locate the error.
I am guessing the bug is in how .Net is handling the display calculations relating to the 2 monitors. So rather than drive myself crazy trying to figure out that bug, I figured if I could prevent the user from clicking on that form, then I would avoid the bug. I know its not the best way to solve a problem but I figured why not give it a shot.
-
Jan 10th, 2008, 09:39 PM
#7
Re: [2005] Reset Mouse Pointer Location On Hover
You'd have to handle the MouseHover event of the TLP rather than the form, or as well as the form, if you want to detect when the user hovers over the TLP.
-
Jan 11th, 2008, 11:10 AM
#8
Thread Starter
Lively Member
Re: [2005] Reset Mouse Pointer Location On Hover
 Originally Posted by jmcilhinney
vb.net Code:
Private Sub Form1_MouseHover(ByVal sender As Object, _
ByVal e As EventArgs) Handles Me.MouseHover
'Move the cursor to the top left corner of
'the screen when it hovers over the form.
Cursor.Position = Point.Empty
End Sub
Does .empty always point to (0,0) on the screen? If I am using 2 montiors, will that position always be on monitor 1 ?
-
Jan 11th, 2008, 08:19 PM
#9
Re: [2005] Reset Mouse Pointer Location On Hover
When you have two monitors your desktop bounds is one big Rectangle spread across the two. Point.Empty is equivalent to New Point(0, 0). This will always be the top, left corner of the desktop bounds. With multiple monitors that will generally be the top, left corner of the primary monitor, but not necessarily. If you have two monitors at different resolutions then part of the desktop bounds will not be visible. Depending on your arrangement (0, 0) may not be visible.
With multiple monitors you may want to use the Screen class to determine the appropriate location. For instance, Screen.PrimaryScreen.WorkingArea.Location will always give you the top, left corner of the desktop on the primary monitor, regardless of monitor resolutions, arrangement and it also takes into account the possibility of the Windows Taskbar beoing at the top of the screen.
Last edited by jmcilhinney; Jan 11th, 2008 at 08:52 PM.
-
Jan 11th, 2008, 08:24 PM
#10
Re: [2005] Reset Mouse Pointer Location On Hover
 Originally Posted by jmcilhinney
This will always be the top right corner of the desktop bounds.
don't you mean top left?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 11th, 2008, 08:51 PM
#11
Re: [2005] Reset Mouse Pointer Location On Hover
 Originally Posted by .paul.
don't you mean top left?
Yeah, I do. I put top left in a couple of other places so I'm not quite sure why I made that mistake.
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
|