Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When i click on a LABEL, what code can i use to determine which label 1

Status
Not open for further replies.

cjLiteStep

Technical User
Mar 12, 2001
18
0
0
CA
hi
i have many labels on a form, and would like to have a piece of code which determines which label was clicked so i can highlite the text in the label on mousedown and return it to normal on mouseup
on each event i would like to run a function which passes the name to a procedure to change the text color
because the label is not the active control when i click it, i can't figure out how to identify it

thanks for any suggestion

cj
 
Labels do not have events associated with them. Clicking them or moving the mouse over them does not trigger an event. This doesn't mean you can't control them and make them behave in a manner of your choosing it just means that the label itself can't be used to trigger these events. Textbox controls, on the other hand, do trigger events. So either change the labels to unbound textbox controls or use the existing textbox controls to control the event behavior you're looking for.
 
jerry
thanks for your reply
labels in fact do have click and mouse up/down events i trigger
however, because a label cannot take the focus it doesn't become the active control
i'm saying there must be a way (other than identifying the active control) to determine which control has has generated the code that runs when it is clicked

cj
 
I'm sorry. You are correct, I had a severe mental moment but I've recovered.

Even though labels cannot accept the focus their properties can be changed. Create a subroutine to change the backstyle property from transparent to normal. Set the backcolor to whatever you want it to be. Then in each event(mousedown and mouseup) of each label pass the label to the subroutine.

Public Sub subToggleLabel(lbl As Label)
If lbl.BackStyle Then
lbl.BackStyle = 0
Else
lbl.BackStyle = 1
End If
End Sub

Private Sub Label1_MouseDown()
subToggleLabel Me.Label1
End Sub

Private Sub Label1_MouseUp()
subToggleLabel Me.Label1
End Sub

Do this for each label you want to toggle.

You could also use the mousemove event. If you do, you'll only want it to toggle the backstyle property to 0 (acNormal) then use the mousemove event for the form to toggle all labels back to transparent.

...
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
ctl.BackStyle = 0
End If
Next
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top