简体   繁体   中英

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 .

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);
}

Using ActiveControl . See this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM