Reputation: 53
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
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.
Upvotes: -1
Reputation: 2812
You can just use the this.ActiveControl
and this is a Control
and you can cast it to ComboBox
Upvotes: 2