Link to home
Start Free TrialLog in
Avatar of MnInShdw
MnInShdwFlag for Japan

asked on

Get Lable Name

It may be a wierd question, but please bear with me.

Me.name returns the active form name.
Is there any method or function that can return the current label/button name?

msgbox Me.Name  in the onclick action of a form, will show a messagebox with the name of the form .
Is it possible to have the same thing for a Button or a Label. (a messagebox with the clicked button/lable).

Imagine I have 2 Labels in a form and a user clicks one of them.
is there any way to find out which one of these labels are clicked?


thank you
ASKER CERTIFIED SOLUTION
Avatar of Runrigger
Runrigger
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Loby333
Loby333

    Private Sub label_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseClick, Label1.MouseClick
        Dim control As Control = CType(sender, Control)
        MessageBox.Show(control.Name)
    End Sub

Open in new window


Hope it helps
Avatar of MnInShdw

ASKER

Screen.ActiveControl.Name doesn't work for labels because
Labels can't accept the focus.

thank you
Upon reading your question, I knew that a label could not accept focus and will therefore never be the currently active control!

I thought you had mistyped the question, so sorry for the confusion.
   Private Sub label_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseClick, Label1.MouseClick
        Dim control As Control = CType(sender, Control)
        MessageBox.Show(control.Name)
    End Sub


Sorry, but I have to admit I can't understand what you mean.
where this sub should be added?
And how I can run this sub?

As far as I know up to Access 2010, OnClick action for controls of a from is  written something like
Private Sub labelname_Click()
and it doesn't receive any parameters.
my bad, sorry
SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Million thanks for your help