/// <summary> /// 清理提示框 /// <summary> public static void ClearToastr() { for (int i = m_lstToastr.Count - 1; i >= 0; i--) { FrmToastr current = m_lstToastr[i]; if (!current.IsDisposed) { current.Close(); current.Dispose(); } } m_lstToastr.Clear(); }
/// <summary> /// 显示提示框 /// </summary> /// <param name="frm">父窗体</param> /// <param name="strMsg">提示信息</param> /// <param name="intAutoColseTime">自动关闭倒计时(ms:毫秒)</param> /// <param name="align">提示框位置</param> /// <param name="state">提示框状态</param> /// <returns>FrmToastr.</returns> private static FrmToastr ShowToastr( Form frm, string strMsg, int intAutoColseTime = 0, ContentAlignment align = ContentAlignment.BottomLeft, ToastrState state = ToastrState.Info) { FrmToastr FrmToastr = new FrmToastr(); FrmToastr.Size = new Size(350, 65); FrmToastr.lblMsg.ForeColor = Color.White; switch (state) { case ToastrState.Success: FrmToastr.pctStat.Image = UC.Controls.Properties.Resources.Success; FrmToastr.BackColor = Color.FromArgb(82, 169, 82); break; case ToastrState.Info: FrmToastr.pctStat.Image = UC.Controls.Properties.Resources.Info; FrmToastr.BackColor = Color.FromArgb(92, 170, 194); break; case ToastrState.Warning: FrmToastr.pctStat.Image = UC.Controls.Properties.Resources.Warning; FrmToastr.BackColor = Color.FromArgb(249, 169, 62); break; case ToastrState.Error: FrmToastr.pctStat.Image = UC.Controls.Properties.Resources.Error; FrmToastr.BackColor = Color.FromArgb(188, 57, 51); break; default: break; } FrmToastr.lblMsg.Text = strMsg; FrmToastr.CloseTime = intAutoColseTime; FrmToastr.btnClose.Visible = true; FrmToastr.ShowAlign = align; FrmToastr.Owner = frm; FrmToastr.m_lstToastr.Add(FrmToastr); FrmToastr.Show(frm); FrmToastr.ReshowToastr(); FrmToastr.BringToFront(); return(FrmToastr); }
/// <summary> /// 警告提示框 /// </summary> /// <param name="frm">当前父窗体</param> /// <param name="strMsg">提示信息</param> /// <returns>FrmToastr.</returns> public static FrmToastr ShowToastrWarning(Form frm, string strMsg) { return(FrmToastr.ShowToastr(frm, strMsg, 3000, ContentAlignment.BottomCenter, ToastrState.Warning)); }
/// <summary> /// 重置位置 /// </summary> public static void ReshowToastr() { lock (FrmToastr.m_lstToastr) { FrmToastr.m_lstToastr.RemoveAll(p => p.IsDisposed == true); var enumerable = from p in FrmToastr.m_lstToastr group p by new { p.ShowAlign }; Size size = Screen.PrimaryScreen.Bounds.Size; foreach (var item in enumerable) { List <FrmToastr> list = FrmToastr.m_lstToastr.FindAll((FrmToastr p) => p.ShowAlign == item.Key.ShowAlign); for (int i = 0; i < list.Count; i++) { FrmToastr FrmToastr = list[i]; switch (item.Key.ShowAlign) { case ContentAlignment.BottomCenter: FrmToastr.Location = new Point((size.Width - FrmToastr.Width) / 2, size.Height - 100 - (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.BottomLeft: FrmToastr.Location = new Point(10, size.Height - 100 - (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.BottomRight: FrmToastr.Location = new Point(size.Width - FrmToastr.Width - 10, size.Height - 100 - (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.MiddleCenter: FrmToastr.Location = new Point((size.Width - FrmToastr.Width) / 2, size.Height - (size.Height - list.Count * (FrmToastr.Height + 10)) / 2 - (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.MiddleLeft: FrmToastr.Location = new Point(10, size.Height - (size.Height - list.Count * (FrmToastr.Height + 10)) / 2 - (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.MiddleRight: FrmToastr.Location = new Point(size.Width - FrmToastr.Width - 10, size.Height - (size.Height - list.Count * (FrmToastr.Height + 10)) / 2 - (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.TopCenter: FrmToastr.Location = new Point((size.Width - FrmToastr.Width) / 2, 10 + (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.TopLeft: FrmToastr.Location = new Point(10, 10 + (i + 1) * (FrmToastr.Height + 10)); break; case ContentAlignment.TopRight: FrmToastr.Location = new Point(size.Width - FrmToastr.Width - 10, 10 + (i + 1) * (FrmToastr.Height + 10)); break; default: break; } } } } }