By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

What do you think of this "SnapToDefaultButton" code?

P: n/a

The code is to snap the mouse cursor to a given button but only if the user
allows it.

I've never read ControPanel values and wonder if there is a better way to
get the info.

The Cursor.Position code was copied from another post.

I sure like to hear if there is a better way but also I'd like confirmation
that this is OK if that is so.


Public Shared Sub SnapToButton(ByVal this As Form, ByVal button As Button)

Dim lCurrentUserKey As RegistryKey =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("C ontrol Panel\Mouse")

If Not lCurrentUserKey Is Nothing Then

Dim GetValue As Integer =
lCurrentUserKey.GetValue("SnapToDefaultButton", -1)

If GetValue = 1 Then


Dim p As New Point

p.X = button.Left + (button.Width \ 2)

p.Y = button.Top + (button.Height \ 2)

Cursor.Position = this.PointToScreen(p)

End If

End If

End Sub
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.