Label On/Off (Form Design Question)


Question

The problem: I would like the label control to change to a raised appearance from its default flat appearance when the user moves the cursor over the control. Easy enough, but the problem is that the control stays that way even if the user moves the cursor away from the label control. Can anyone suggest a way to have the label control return to its default appearance when the cursor is moved off the control? Again, I would prefer not to use command buttons (unless someone can tell me a way to control their appearance more precisely).

Answer

From: Shamil Salakhetdinov <shamil@marta.darts.spb.ru>
To: ACCESS-L <ACCESS-L@PEACH.EASE.LSOFT.COM>
Subject: Re: Form Design Question
Date: 23 June 1998 22:22

Joe,

Enclosed code sample should do the trick.

HTH,
Shamil

P.S. If you place your label control too close to the form's borders you can have them left
raised - I don't know how to solve this problem - if you find its solution please e-mail it me...

P.P.S. The code:

Private mstrLastCtlName As String

Private Function LblCtlRaiseOnOff(ByRef rfrm As Form, _
                                  ByVal vstrCtlName As String, _
                                  ByVal vlbnOn As Boolean)
    Dim ctl As Label
    
    If vstrCtlName = "" Then Exit Function
    
    If mstrLastCtlName <> vstrCtlName Then
        LblCtlRaiseOnOff Me, mstrLastCtlName, False
    End If
    
    Set ctl = Me(vstrCtlName)
    If vlbnOn Then
        ctl.SpecialEffect = 1
        'DoEvents
    Else
        ctl.SpecialEffect = 0
        'DoEvents
    End If
    mstrLastCtlName = vstrCtlName
End Function

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        LblCtlRaiseOnOff Me, mstrLastCtlName, False
End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        LblCtlRaiseOnOff Me, mstrLastCtlName, False
End Sub


Private Sub Label0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    LblCtlRaiseOnOff Me, "Label0", True
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    LblCtlRaiseOnOff Me, "Label1", True
End Sub

Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    LblCtlRaiseOnOff Me, "Label2", True
End Sub

 


HOME    TOPICS

Copyright © 1998–1999 by Shamil Salakhetdinov.
All rights reserved. Terms of use.

Last updated: October 10, 2006

Published also here at 4TOPS: Label On/Off (Form Design Question)