/// <summary> /// 弹出 /// </summary> public static void Show(this object ex, Control obj, string title, LeveType type, bool sync = true) { if (ex == null) { return; } string msg = ex.ToString(); if (ex is Exception exc) { Log(exc); msg = exc.Message(); if (!title.IsNullOrEmpty()) { msg = string.Format("{0}\r\n{1}", title, msg); } if (type == LeveType.None) { type = exc.InnerException() is WarningException ? LeveType.Warn : LeveType.Error; } } else if (type == LeveType.None) { type = LeveType.Warn; } try { obj = TMethod.TopForm(obj); title = Text; if (title.IsNullOrEmpty() && obj != null && !obj.IsDisposed) { title = obj.Text; } if (sync) { new Action <Control, string, string, LeveType, bool>(Show).BeginInvoke(obj, title, msg, type, ex is Exception, null, null); } else { Show(obj, title, msg, type, ex is Exception); } } finally { Application.DoEvents(); } }
private static void Show(Control obj, string title, string msg, LeveType type, bool iError) { MessageBoxIcon icon = MessageBoxIcon.Information; switch (type) { case LeveType.Warn: icon = MessageBoxIcon.Warning; break; case LeveType.Error: icon = MessageBoxIcon.Error; break; } if (obj == null || !obj.Visible || obj.IsDisposed) { Show(null, title, msg, icon, iError); } else { obj.Invoke(new Action <Control, string, string, MessageBoxIcon, bool>(Show), new object[] { obj, title, msg, icon, iError }); } }
/// <summary> /// 弹出 /// </summary> public static void Show(this object ex, string title, LeveType type, bool sync = true) { Show(ex, null, title, type, sync); }
/// <summary> /// 弹出 /// </summary> public static void Show(this string msg, LeveType type, bool sync = true) { Show(msg, null, null, type, sync); }