欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

winfrom 获取焦点控件

程序员文章站 2023-11-08 21:10:58
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)] internal static extern IntPtr GetFocus(); ///获取 当前拥有焦点 ......
[dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.winapi)]
        internal static extern intptr getfocus();
        ///获取 当前拥有焦点的控件
        private control getfocusedcontrol()
        {
            control focusedcontrol = null;
            intptr focusedhandle = getfocus();
            if (focusedhandle != intptr.zero)
            focusedcontrol = control.fromchildhandle(focusedhandle);
            return focusedcontrol;
        }

原文连接: