开发者

How to get the form active control?

开发者 https://www.devze.com 2023-01-01 04:07 出处:网络
Is there a way to get the form active control? I was checking in the help for the \"Support.GetActive开发者_开发问答Control\" method but it isn\'t supported :) for the Compact Framework.

Is there a way to get the form active control?

I was checking in the help for the "Support.GetActive开发者_开发问答Control" method but it isn't supported :) for the Compact Framework.

I suppose that I can track the focus by adding a custom GotFocus event handler to all the form controls, but I'm looking for a more generic way that can be implemented for any form.


This example displays the name of the currently selected Windows Forms control in a Label control.

private void DisplayNameOfActiveControl()
{
    label1.Text = this.ActiveControl.Name;
}


You can iterate over all the controls in the form and check which one is focused.

Example: Getting ActiveControl in Compact Framework

0

精彩评论

暂无评论...
验证码 换一张
取 消