473,836 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open some dialog boxes and the mouse cursor moves to one of the dialog buttons

Open some dialog boxes and the mouse cursor moves to one of the dialog
buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want the
cursor and move it.
Or does DotNet help somehow?

Thanks
Nov 21 '05 #1
8 2155
Here you go.
Create a form with a button on it, and then paste in the following code:

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer,
ByVal Y As Integer) As Long
Public Declare Function ClientToScreen Lib "user32" (ByVal hWnd As
IntPtr, ByRef point As POINT) As Boolean

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim p As New POINT
p.x = Button1.Left + (Button1.Width / 2)
p.y = Button1.Top + (Button1.Height / 2)
ClientToScreen( Me.Handle, p)
SetCursorPos(p. x, p.y)
End Sub

- Scott Swigart

P.S. Moving the mouse for the user is generally considered a no-no.

"**Develope r**" wrote:
Open some dialog boxes and the mouse cursor moves to one of the dialog
buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want the
cursor and move it.
Or does DotNet help somehow?

Thanks

Nov 21 '05 #2
In Windows XP, you can set the options for the mouse to jump to the default
button when a form is opened I think.
--
Dennis in Houston
"Scott Swigart" wrote:
Here you go.
Create a form with a button on it, and then paste in the following code:

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer,
ByVal Y As Integer) As Long
Public Declare Function ClientToScreen Lib "user32" (ByVal hWnd As
IntPtr, ByRef point As POINT) As Boolean

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim p As New POINT
p.x = Button1.Left + (Button1.Width / 2)
p.y = Button1.Top + (Button1.Height / 2)
ClientToScreen( Me.Handle, p)
SetCursorPos(p. x, p.y)
End Sub

- Scott Swigart

P.S. Moving the mouse for the user is generally considered a no-no.

"**Develope r**" wrote:
Open some dialog boxes and the mouse cursor moves to one of the dialog
buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want the
cursor and move it.
Or does DotNet help somehow?

Thanks

Nov 21 '05 #3
SetCursorPos is actually Boolean, not Long.

Roman

"Scott Swigart" <sc***@swigartc onsulting.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ ×
ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:83******** *************** ***********@mic rosoft.com...
Here you go.
Create a form with a button on it, and then paste in the following code:
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Function ClientToScreen Lib "user32" (ByVal hWnd As
IntPtr, ByRef point As POINT) As Boolean

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim p As New POINT
p.x = Button1.Left + (Button1.Width / 2)
p.y = Button1.Top + (Button1.Height / 2)
ClientToScreen( Me.Handle, p)
SetCursorPos(p. x, p.y)
End Sub

- Scott Swigart

P.S. Moving the mouse for the user is generally considered a no-no.

"**Develope r**" wrote:
Open some dialog boxes and the mouse cursor moves to one of the dialog buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want the cursor and move it.
Or does DotNet help somehow?

Thanks

Nov 21 '05 #4
**Developer**,
First I would like to strongly suggest you don't implement it. As a number
of users find it *rude* for a program to move their mouse for them.
Here is a version of Scott's code that does not use P/Invoke (Declare
statements).

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim p As New Point
p.X = Button1.Left + (Button1.Width \ 2)
p.Y = Button1.Top + (Button1.Height \ 2)
Cursor.Position = Me.PointToScree n(p)
End Sub

Both Win32 APIs are already exposed in the Framework, no need to use
Declare...

Hope this helps
Jay

" **Developer**" <RE************ *@a-znet.com> wrote in message
news:eR******** ******@TK2MSFTN GP14.phx.gbl...
| Open some dialog boxes and the mouse cursor moves to one of the dialog
| buttons.
| I'd like to implement that .
| Is that simply something I have to program, i.e. figure out where I want
the
| cursor and move it.
| Or does DotNet help somehow?
|
| Thanks
|
|
Nov 21 '05 #5

**Developer** wrote:
Open some dialog boxes and the mouse cursor moves to one of the dialog
buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want the
cursor and move it.
Or does DotNet help somehow?


As others have said, you shoudl carefully consider if you really want
your application to dictate this behaviour.

Since Windows 2000 (I believe), users have had the ability to set this
behaviour on a *global* level (eg in XP it is in Control Panel | Mouse
| Pointer Options | Snap To), and by implication if they have *not* set
this option, it means that they *do not* want this behaviour. For one
application to behave in this way regardless of the global setting
would I think be seen as extremely unfriendly.

--
Larry Lard
Replies to group please

Nov 21 '05 #6
Thanks to all.

As to the suggestions against it I note that MS does it often.
For example, Open Notepad/File/Open
If there is a way for the user to turn it on/off I'd sure like to know how
to read his setting.
How can I check the user settings?

At first I didn't like it but then got used to it.

Something else I don't like is sometimes I want to delete one character or
move one character left and the insertion point moves to the start of the
line. I can't remember exactly what it is but I know when it has happened I
did not like it. Wish I could shut that feature off.
Thanks again
" **Developer**" <RE************ *@a-znet.com> wrote in message
news:eR******** ******@TK2MSFTN GP14.phx.gbl...
Open some dialog boxes and the mouse cursor moves to one of the dialog
buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want
the cursor and move it.
Or does DotNet help somehow?

Thanks

Nov 21 '05 #7
Larry is correct in XP it can be set in controlpanel.
Then it doesn't have to be implemented.
Simply declare the default button and the rest is automatic.
I didn't try but I'd guess it also works with MessageBox if the default
button is specified.

" **Developer**" <RE************ *@a-znet.com> wrote in message
news:eR******** ******@TK2MSFTN GP14.phx.gbl...
Open some dialog boxes and the mouse cursor moves to one of the dialog
buttons.
I'd like to implement that .
Is that simply something I have to program, i.e. figure out where I want
the cursor and move it.
Or does DotNet help somehow?

Thanks

Nov 21 '05 #8
Larry,
Thanks for the reminder: XP Pro has a similar option available as does
Windows Server 2003.

Hope this helps
Jay
"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
|
| **Developer** wrote:
| > Open some dialog boxes and the mouse cursor moves to one of the dialog
| > buttons.
| > I'd like to implement that .
| > Is that simply something I have to program, i.e. figure out where I want
the
| > cursor and move it.
| > Or does DotNet help somehow?
|
| As others have said, you shoudl carefully consider if you really want
| your application to dictate this behaviour.
|
| Since Windows 2000 (I believe), users have had the ability to set this
| behaviour on a *global* level (eg in XP it is in Control Panel | Mouse
|| Pointer Options | Snap To), and by implication if they have *not* set
| this option, it means that they *do not* want this behaviour. For one
| application to behave in this way regardless of the global setting
| would I think be seen as extremely unfriendly.
|
| --
| Larry Lard
| Replies to group please
|
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6232
by: John Champaign | last post by:
Hi all, I'm working on an educational applet for a child with special needs. He's got a bit of a trick to make my life more difficult... To interact with the applet he needs to click on buttons, which is fine most of the time (he comes from a Mac environment, so I accept mouse clicks from the right or left button when he's working on the PC). But every once in a while, he'll press and hold the right mouse button, move onto a JButton,...
7
2451
by: fernandoronci | last post by:
Hi, I've been given the task of mantaining and fixing a website which I didn't design. I'm using Internet Explorer 5.5 and 6.x. Specifically, the problem is that navigation menues (written in javascript) don't disappear when the mouse moves outside of the area of the menues (some of the menues are nested two and three levels). As long as the mouse cursor remains *within* the options of the menues, the option under the mouse cursor is...
5
7102
by: Logan Mckinley | last post by:
I need to know where the cursor is (x,y) and when it moves even when it is not over my form. I know i can get the current location with: System.Windows.Forms.Cursor.Position.X System.Windows.Forms.Cursor.Position.X But that does not raise an event and using a timer would be to processor intensive. In MFC you would write a mousehook to solve this problem but when i run the C# MouseHook code for from MSDN...
0
1380
by: Raj Chudasama | last post by:
In dot net 2003 on Xp when you go to the file menu and select Open file a dialog box opens up on the left hand side there are items such as history My Projects Desktop Favorites My Network places
3
4884
by: Steve Long | last post by:
I hope this isn't too stupid of a question but I'm looking for a way to change an item in a listview control when the mouse moves over it. I'd like to change its color and underline it for a probable internet link. Is there a way to do that? I've looked through the help and can't find anything that, well, helps. Perhaps I'm using the wrong control. Any help would be appreciated. Thanks Steve
3
3771
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim pt As Point Dim wnd As IntPtr Const WM_LBUTTONUP = &H202 '//LButton up Const WM_LBUTTONDOWN = &H201 '//LButton down
0
1538
by: GeoffT | last post by:
I have encountered a problem with the data that is displayed in the list boxes that are located on a tab control access form (2003 version). This form uses several combo boxes as filters (After Update and On Got Focus) to display info on the list box of the form. The info is correct. The problem that I am having pertains to the screen continues to flash as the cursor moves over certain other items on the form (i.e. Command Buttons / Text...
4
6980
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the measurement, but it's an auditing function and that's acceptable.
0
2316
by: Studlyami | last post by:
I am trying to find how windows translate the input from a HID device to an actual windows message; specifically, the mouse. I am trying to figure out how when the mouse moves the process windows takes in order to ensure all windows receive the notification that the mouse moved and how windows moves the mouse cursor. What process handles the movement of the mouse cursor and at what point does windows move the mouse cursor vs posting the...
0
9818
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10843
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.