janus Mack
janus Mack

Reputation: 53

Get name of focused control on the Form

Is it even possible to get the name of the ComboBox that is focused? I would like a label to show the name.

Upvotes: 1

Views: 1538

Answers (2)

Creator
Creator

Reputation: 1512

Lets say you have 3 comboboxes on your form and a label.

Add the code for a combobox enter event.
And in this code you will use the sender to get the name of the combobox and display it in the label.

private void CBox_Enter(object sender, EventArgs e)
    {
        Control CBox = (Control)sender;
        label1.Text = CBox.Name;
    }

Then you need to select all the comboboxes you want to use, to add CBox_Enter to all the comboboxes enter event.

enter image description here

Upvotes: -1

Mehdi Khademloo
Mehdi Khademloo

Reputation: 2812

You can just use the this.ActiveControl and this is a Control and you can cast it to ComboBox

Upvotes: 2

Related Questions