[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; }
原文鏈接:https://blog.csdn.net/alisa525/article/details/7402307api