private static void Show(Control obj, string title, string msg, MessageBoxIcon icon, bool iError) { if (icon == MessageBoxIcon.Error && iError && ErrorLogEvent != null) { ErrorLogEvent.Invoke(msg); return; } if (obj == null || !obj.Visible || obj.IsDisposed) { MessageBox.Show(msg, title, MessageBoxButtons.OK, icon); } else { Win32Helper.SwitchToThisWindow(obj.Handle, true); MessageBox.Show(obj, msg, title, MessageBoxButtons.OK, icon); } }
/// <summary> /// 获取顶层窗体 /// </summary> public static Control TopForm(Control obj = null) { while (obj is Control && !(obj is Form)) { if (obj.Parent == null) { break; } obj = obj.Parent; } if (obj == null || !obj.Visible || obj.IsDisposed || !(obj is Form)) { obj = LoadHelper.Form; } if (obj == null || !obj.Visible || obj.IsDisposed || !(obj is Form)) { obj = ExceptionHelper.Form; if (obj == null) { IntPtr handle = Win32Helper.GetForegroundWindow(); obj = Control.FromChildHandle(handle); } if (obj == null) { for (int i = Application.OpenForms.Count - 1; i >= 0; i--) { var item = Application.OpenForms[i]; if (item.GetType().Name != "SkinForm") { obj = item; break; } } } } return(obj); }