C#获取当前窗体的受焦控件。

来源:互联网 发布:淘宝账号免费注册 编辑:程序博客网 时间:2024/06/07 06:31
        Control GetFocusedControl(Control ctrl)
        {
            foreach (Control c in ctrl.Controls)
            {

                if (c.Focused == false)
                {
                    GetFocusedControl(c);
                }
     
                        return c;
            }

            return null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
           Control c= GetFocusedControl(this);
        }