What do you think of this "SnapToDefaultButton" code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • **Developer**

    What do you think of this "SnapToDefaultButton" code?



    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.

    Thanks



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

    Dim lCurrentUserKey As RegistryKey =
    Microsoft.Win32 .Registry.Curre ntUser.OpenSubK ey("Control Panel\Mouse")

    If Not lCurrentUserKey Is Nothing Then

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

    If GetValue = 1 Then

    button.NotifyDe fault(True)

    Dim p As New Point

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

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

    Cursor.Position = this.PointToScr een(p)

    End If

    End If

    End Sub


Working...