知道谁得到了失去焦点事件焦点 [英] Know who got the focus in a Lost Focus event

查看:130
本文介绍了知道谁得到了失去焦点事件焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能知道谁得到了在一个失去焦点事件的焦点?

Is it possible to know who got the focus in a lost focus event?

Compact Framework不具有 ACTIVECONTROL ,所以我不知道如何告诉谁的焦点。

Compact Framework does not have an ActiveControl, so I don't know how to tell who got the focus.

推荐答案

这是结束了工作的解决方案:

This is the solution that ended up working:

public System.Windows.Forms.Control FindFocusedControl()
{
    return FindFocusedControl(this);
}

public static System.Windows.Forms.Control FindFocusedControl(System.Windows.Forms.Control container)
{
    foreach (System.Windows.Forms.Control childControl in container.Controls)
    {
        if (childControl.Focused)
        {
            return childControl;
        }
    }

    foreach (System.Windows.Forms.Control childControl in container.Controls)
    {
        System.Windows.Forms.Control maybeFocusedControl = FindFocusedControl(childControl);
        if (maybeFocusedControl != null)
        {
            return maybeFocusedControl;
        }
    }

    return null; // Couldn't find any, darn!
}

这篇关于知道谁得到了失去焦点事件焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆