Hallo
this is a question about how to point the mouse to the center of a button when opening a userform.
Please see attached workbook.
Your help is apprechiated. Thank you.
Barb
Hallo
this is a question about how to point the mouse to the center of a button when opening a userform.
Please see attached workbook.
Your help is apprechiated. Thank you.
Barb
Thank you, Roy.
I know the focus function. But I want to move the mouse to the middle of the button.
My problem is to find the right coordinates in order to use SetCursorPos.
Why do you need that? The SetCursorPos
line positions your mouse cursor relative to the top left of your screen (position 0, 0).
Why do I need that?
For the convinience of the user.
The Userform is opened by a museclick. So when the mosue is over the preferred button when opening the userform it is convinient just to click again.
For the coordinates I hate to add the UF coordinates and the Butto coordinates and the half lengh/width of the button. But for any reason it does not work this way,
So I posted a document here earlier. If you know, how to do it, I would like to ask you, or anybody else, to show me, how to set the mouse position to the button.
Thank You.
Hello,
In order to get/set the cursor position, you do need to make a Windows API call
see link :
https://support.microsoft.com/…o-get-set-cursor-position
Hope this will help
The button has to have focus to be clicked so why is SetFocus not good enough or setting Tab Order?
The focus referres to Enter-key, but not to the mouse position.
The mouse remains at the position where I clicked to call the Userform. (Sorry, my english maybe not good)
But the mouse should move to the Cancel-Button of the userform, see my example uploaded earlier.
SetFocus can refer to any control. With a TextBox you can show the cursor by using SelLength, if the TextBox contains Text
I really do not think that SetCursor will do what you want on a UserForm. If you set the Default Property of the Cancel Button to True then when the user opens the form and clicks Enter on the keyboard the Cancel button will run. If the user clicks a different button then to reset the cancel button to default a TextBox would need to be clicked.
Re,
Have you tested the Windows API call ... ???
I have tested it, but I think it refers to the monitor position and the focus is not on the UserForm. Also, I get different positions each time I run it.
Load the UserForm and the Cancel Button has focus, click the enter button and the Close Button runs.
When the userform is active you can click the other button to get the cursor position, it does vary each time.
OK, I got the cursor position and typed into the code manually. Now I can click to open the UF and quickly click again to click the button, without moving the mouse.
I wonder why it is not possible to get it with the x/y of the userform window plus the x/y of the button.
Thank you. Lob
That's what the default Property achieves.
Don’t have an account yet? Register yourself now and be a part of our community!