开发者

How to get the form active control?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜