[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]        internal static extern IntPtr GetFocus();        private Control GetFocusedControl()
        {            Control focusedControl = null;            // To get hold of the focused control:             IntPtr focusedHandle = GetFocus();            if (focusedHandle != IntPtr.Zero)                // Note that if the focused Control is not a .Net control, then this will return null.                 focusedControl = Control.FromHandle(focusedHandle);            return focusedControl;        }

解决方案 »

  1.   

    GetFocus();获得焦点
    focusedControl = Control.FromHandle(focusedHandle); 获得焦点的控件
      

  2.   

    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)] //引用系统user32dll  internal static extern IntPtr GetFocus();   //user32中的获取焦点函数  private Control GetFocusedControl()      //这应当是一个自定义的控件函数
      {  Control focusedControl = null;        //设置为空  // To get hold of the focused control:    IntPtr focusedHandle = GetFocus();   //getfocus()获得焦点  if (focusedHandle != IntPtr.Zero)     // Note that if the focused Control is not a .Net control, then this will return null.    focusedControl = Control.FromHandle(focusedHandle);     return focusedControl;