/// <summary> /// 为控件设置输入焦点。 /// </summary> /// <param name="hWnd">控件句柄。</param> /// <returns>如果输入焦点请求成功,则为 true;否则为 false。</returns> public static bool Focus(IntPtr hWnd) { if (GetCanFocus(hWnd)) { UnsafeNativeMethods.SetFocus(hWnd); } return(GetFocused(hWnd)); }
internal bool MessageBoxWithFocusRestore(string message, MessageBoxButton buttons, MessageBoxImage image) { bool result = false; IntPtr focus = UnsafeNativeMethods.GetFocus(); try { result = (MessageBox.Show(message, this.DialogCaption, buttons, image, MessageBoxResult.OK, MessageBoxOptions.None) == MessageBoxResult.Yes); } finally { UnsafeNativeMethods.SetFocus(new HandleRef(this, focus)); } return(result); }