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
 
 
 
 
 
TitleMake an ActiveX control that highlights itself when the mouse is over it
KeywordsActiveX control, highlight
CategoriesActiveX, ActiveX Controls, Graphics, Multimedia
 
In the control's label's MouseMove event handler, see if the control is already highlighted. If it is not, highlight it and enable a Timer.

When the Timer's event fires, use the ScreenToClient and GetCursorPos API functions to see if the mouse is still over the control. If the mouse has moved off of the control, unhighlight it and disable the Timer.

My book Custom Controls Library includes the implementation for 101 custom controls (although not this one).

 
Private Sub Label1_MouseMove(Button As Integer, Shift As _
    Integer, x As Single, y As Single)
    If highlighted Then Exit Sub
    highlighted = True
    Label1.ForeColor = vbRed
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim pt As POINTAPI

    ' See where the cursor is.
    GetCursorPos pt
    
    ' Translate into window coordinates.
    ScreenToClient hwnd, pt

    ' See if we're still within the control.
    If pt.x < Label1.Left Or pt.y < Label1.Top Or _
       pt.x > Label1.Left + Label1.Width Or _
       pt.y > Label1.Top + Label1.Height _
    Then
        highlighted = False
        Label1.ForeColor = vbBlack
        Timer1.Enabled = False
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated