Farna
Farna

Reputation: 1176

how can understand which control has been focused?

I have many controls that i make in run time and i locate them in my panel on the form,now i want to delete each control that the user selected ,how can i understand that which control has been focused ?? thanks .

Upvotes: 2

Views: 2020

Answers (2)

kyrylomyr
kyrylomyr

Reputation: 12632

Generally, you need FocusManager.GetFocusedElement if you are using WPF or Form.ActiveControl for WinForms.

For panel it will be:

if (panel.ContainsFocus)
{
    Control currentlyFocused =
        panel.Controls.Cast<Control>().FirstOrDefault(control => control.Focused);
}

Upvotes: 5

Kumar
Kumar

Reputation: 1015

Using ActiveControl. See this

Upvotes: 0

Related Questions