Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleUse API capture functions to make a button that changes its caption when the mouse moves over it
Keywordsbutton, caption, mouse over
CategoriesControls, API, Tips and Tricks
 
Thanks to Sergio Perciballi.

When the mouse moves over the button, use the GetCapture function to see what window has the mouse captured. If it is not this button, use SetCapture to capture mouse events.

When the MouseMove event occurs and the cursor has left the button's area, use ReleaseCapture to release the capture.

 
Private Sub Check1_MouseMove(Index As Integer, Button As _
    Integer, Shift As Integer, X As Single, Y As Single)
    If (X < 0) Or (Y < 0) Or (X > Check1(Index).Width) Or _
        (Y > Check1(Index).Height) Then
        '        ' the MOUSELEAVE pseudo-event
        ReleaseCapture
        '        ' in this example revert the caption to
        ' normal
        Check1(Index).Font.Bold = False
        Check1(Index).ForeColor = vbBlack
        '
    ElseIf GetCapture() <> Check1(Index).hwnd Then
        '        ' the MOUSEENTER pseudo-event
        SetCapture Check1(Index).hwnd

        Check1(Index).Font.Bold = True
        Check1(Index).ForeColor = vbRed
    End If
End Sub

Private Sub Command1_MouseMove(Index As Integer, Button As _
    Integer, Shift As Integer, X As Single, Y As Single)

    If (X < 0) Or (Y < 0) Or (X > Command1(Index).Width) Or _
        (Y > Command1(Index).Height) Then
        '        ' the MOUSELEAVE pseudo-event
        ReleaseCapture
        '        ' in this example revert the caption to
        ' normal

        Command1(Index).Font.Bold = False
        '
    ElseIf GetCapture() <> Command1(Index).hwnd Then
        '        ' the MOUSEENTER pseudo-event
        SetCapture Command1(Index).hwnd

        Command1(Index).Font.Bold = True
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated