Home All Groups Group Topic Archive Search About

How to Move Mouse to Control with Focus

Author
7 Apr 2005 8:14 PM
Michael D Murphy
Hi,
I have win app in which I need to move the mouse to the textbox field that
has the focus and then hide the mouse pointer.
Any tips on how to do these two things would be appreciated.
Thanks,
Michael Murphy

Author
7 Apr 2005 8:46 PM
Oenone
Michael D Murphy wrote:
> I have win app in which I need to move the mouse to the textbox field
> that has the focus and then hide the mouse pointer.

If you're really sure you want to do that, bearing in mind it may irritate
your users, you can do it as follows.

To move the mouse cursor to the control that has focus:

        Windows.Forms.Cursor.Position = _
                        Me.ActiveControl.PointToScreen(New Point(0, 0))

This will put the cursor at the exact top/left of the control. If you change
the (0,0) to different numbers, this will offset the cursor from that
position.

To hide the cursor:

        Windows.Forms.Cursor.Hide()

This will hide it as long as it remains over your application; if the
pointer is moved over a different application it will still appear.

Hope that helps,

--

(O) e n o n e
Author
7 Apr 2005 8:53 PM
Michael D Murphy
(O) e n o n e,
Thanks for your help.
This is a kiosk type XP Embedded Win App that offers the user no mouse or
keyboard interaction. But I did tie a real push button on the front panel so
the user can print a coupon for what he/she is looking at. Kinda complex to
explain, but thanks again for the code snippet!!
Michael
Show quoteHide quote
"Oenone" <oen***@nowhere.com> wrote in message
news:X_g5e.11829$S9.5623@newsfe5-gui.ntli.net...
> Michael D Murphy wrote:
>> I have win app in which I need to move the mouse to the textbox field
>> that has the focus and then hide the mouse pointer.
>
> If you're really sure you want to do that, bearing in mind it may irritate
> your users, you can do it as follows.
>
> To move the mouse cursor to the control that has focus:
>
>        Windows.Forms.Cursor.Position = _
>                        Me.ActiveControl.PointToScreen(New Point(0, 0))
>
> This will put the cursor at the exact top/left of the control. If you
> change
> the (0,0) to different numbers, this will offset the cursor from that
> position.
>
> To hide the cursor:
>
>        Windows.Forms.Cursor.Hide()
>
> This will hide it as long as it remains over your application; if the
> pointer is moved over a different application it will still appear.
>
> Hope that helps,
>
> --
>
> (O) e n o n e
>
>
Author
7 Apr 2005 9:52 PM
Michael D Murphy
(O) e n o n e
When I am debugging :
Windows.Forms.Cursor.Position = Me.ActiveControl.PointToScreen(New Point(0,
0))

I get an Object Not Set to a reference Exception, even though I have the
following line of code right above it.
txtParkHere.Focus()

Obviously I am doing something wrong. When I look at the value of
ActiveControl, it is set to Nothing.
Thanks for your time.
Michael

Show quoteHide quote
"Michael D Murphy" <mdmur***@scs-techresources.com> wrote in message
news:efr$MP7OFHA.3880@tk2msftngp13.phx.gbl...
> (O) e n o n e,
> Thanks for your help.
> This is a kiosk type XP Embedded Win App that offers the user no mouse or
> keyboard interaction. But I did tie a real push button on the front panel
> so the user can print a coupon for what he/she is looking at. Kinda
> complex to explain, but thanks again for the code snippet!!
> Michael
> "Oenone" <oen***@nowhere.com> wrote in message
> news:X_g5e.11829$S9.5623@newsfe5-gui.ntli.net...
>> Michael D Murphy wrote:
>>> I have win app in which I need to move the mouse to the textbox field
>>> that has the focus and then hide the mouse pointer.
>>
>> If you're really sure you want to do that, bearing in mind it may
>> irritate
>> your users, you can do it as follows.
>>
>> To move the mouse cursor to the control that has focus:
>>
>>        Windows.Forms.Cursor.Position = _
>>                        Me.ActiveControl.PointToScreen(New Point(0, 0))
>>
>> This will put the cursor at the exact top/left of the control. If you
>> change
>> the (0,0) to different numbers, this will offset the cursor from that
>> position.
>>
>> To hide the cursor:
>>
>>        Windows.Forms.Cursor.Hide()
>>
>> This will hide it as long as it remains over your application; if the
>> pointer is moved over a different application it will still appear.
>>
>> Hope that helps,
>>
>> --
>>
>> (O) e n o n e
>>
>>
>
>
Author
7 Apr 2005 10:04 PM
Michael D Murphy
Well, never mind, I see I should be using the txtParkHere.Select() method.
Thanks Again.
Michael
Show quoteHide quote
"Michael D Murphy" <mdmur***@scs-techresources.com> wrote in message
news:%23Pshaw7OFHA.1176@TK2MSFTNGP12.phx.gbl...
> (O) e n o n e
> When I am debugging :
> Windows.Forms.Cursor.Position = Me.ActiveControl.PointToScreen(New
> Point(0, 0))
>
> I get an Object Not Set to a reference Exception, even though I have the
> following line of code right above it.
> txtParkHere.Focus()
>
> Obviously I am doing something wrong. When I look at the value of
> ActiveControl, it is set to Nothing.
> Thanks for your time.
> Michael
>
> "Michael D Murphy" <mdmur***@scs-techresources.com> wrote in message
> news:efr$MP7OFHA.3880@tk2msftngp13.phx.gbl...
>> (O) e n o n e,
>> Thanks for your help.
>> This is a kiosk type XP Embedded Win App that offers the user no mouse or
>> keyboard interaction. But I did tie a real push button on the front panel
>> so the user can print a coupon for what he/she is looking at. Kinda
>> complex to explain, but thanks again for the code snippet!!
>> Michael
>> "Oenone" <oen***@nowhere.com> wrote in message
>> news:X_g5e.11829$S9.5623@newsfe5-gui.ntli.net...
>>> Michael D Murphy wrote:
>>>> I have win app in which I need to move the mouse to the textbox field
>>>> that has the focus and then hide the mouse pointer.
>>>
>>> If you're really sure you want to do that, bearing in mind it may
>>> irritate
>>> your users, you can do it as follows.
>>>
>>> To move the mouse cursor to the control that has focus:
>>>
>>>        Windows.Forms.Cursor.Position = _
>>>                        Me.ActiveControl.PointToScreen(New Point(0, 0))
>>>
>>> This will put the cursor at the exact top/left of the control. If you
>>> change
>>> the (0,0) to different numbers, this will offset the cursor from that
>>> position.
>>>
>>> To hide the cursor:
>>>
>>>        Windows.Forms.Cursor.Hide()
>>>
>>> This will hide it as long as it remains over your application; if the
>>> pointer is moved over a different application it will still appear.
>>>
>>> Hope that helps,
>>>
>>> --
>>>
>>> (O) e n o n e
>>>
>>>
>>
>>
>
>