How to Move Mouse to Control with Focus

  • Thread starter Michael D Murphy
  • Start date
M

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
 
O

Oenone

Michael said:
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,
 
M

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
 
M

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
 
M

Michael D Murphy

Well, never mind, I see I should be using the txtParkHere.Select() method.
Thanks Again.
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top