private void ShowClose(string text, HintIconType iconType, int atLeastDuration, int atMostDuration, Form parentForm) { //this.Text = caption; this.TopMost = true; f_Text = text; //AdjustUIByHintInfo(f_Text,ref atLeastDuration); lblInfo.Text = text; this.Height = pnlTop.Height + pnlBottom.Height + lblInfo.Height + 15; this.Width = pnlIcon.Width + pnlRight.Width + lblInfo.Width + 10; f_IconType = iconType; pnlIcon.BackgroundImage = null; switch (f_IconType) { case HintIconType.OK: pnlIcon.BackgroundImage = ParamsSettingTool.Properties.Resources.OK_32; break; case HintIconType.Warning: pnlIcon.BackgroundImage = ParamsSettingTool.Properties.Resources.warning_32; break; case HintIconType.Err: pnlIcon.BackgroundImage = ParamsSettingTool.Properties.Resources.Error_32; break; default: pnlIcon.BackgroundImage = null; break; } int byteLen = Encoding.GetEncoding("GBK").GetByteCount(text); int addDuration = 0; if (byteLen > 10) { addDuration = (byteLen - 10) * 75; } f_DurationTime = atLeastDuration + addDuration; f_LeftTime = f_DurationTime - SHOW_TIME - CLOSE_TIME; f_MaxDurationTime = atMostDuration; if (f_LeftTime < 0) { f_LeftTime = 0; } else if (f_LeftTime > f_MaxDurationTime) { f_LeftTime = f_MaxDurationTime; } f_CountTimer.Start(); parentForm = FindTopParentForm(parentForm); if (parentForm != null && parentForm.IsHandleCreated && parentForm.Visible) { this.StartPosition = FormStartPosition.Manual; Point pt = new Point((parentForm.Width - this.Width) / 2, (parentForm.Height - this.Height) / 2); this.Location = new Point(pt.X + parentForm.Left, pt.Y + parentForm.Top); } this.ShowDialog(); }
public static void ShowHint(string text, HintIconType iconType, int atLeastDuration, int atMostDuration, Form parentForm, bool waitForClose) { var tsk = new Task(() => { AutoCloseDialog dlg = new AutoCloseDialog(); dlg.ShowClose(text, iconType, atLeastDuration, atMostDuration, parentForm); }); tsk.Start(); if (waitForClose) { tsk.Wait(); } }
///// <summary> ///// 启动百分比进度条 ///// </summary> ///// <param name="total">进度总值</param> ///// <param name="message">提示信息</param> ///// <param name="callback">Hint回调返回参数</param> //public static void StartProgress(SynchronizationContext uiContext, int total, string message, Action<HintArgs> callback = null) //{ // ProgressFormManage.Singleton.StartProgress(uiContext, total, message, callback); //} ///// <summary> ///// 百分比进度条 ///// </summary> ///// <param name="current">当前进度值</param> ///// <param name="message">提示消息</param> //public static void ShowProcess(int current, string message) //{ // ProgressFormManage.Singleton.ShowProgress(current, message); //} ///// <summary> ///// 关闭百分比进度条 ///// </summary> //public static void ProcessDone() //{ // ProgressFormManage.Singleton.ShowProgress(int.MaxValue, ""); //} /// <summary> /// 自动隐藏提示框 /// </summary> /// <param name="parentForm">所有者,影响显示位置,为null时屏幕居中</param> /// <param name="text"></param> /// <param name="iconType"></param> /// <param name="atLeastDuration"></param> /// <param name="atMostDuration"></param> /// <param name="waitForClose"></param> public static void ShowAutoCloseDialog(Form parentForm, string text, HintIconType iconType = HintIconType.OK, int atLeastDuration = 1500, int atMostDuration = 5000, bool waitForClose = false) { AutoCloseDialog.ShowHint(text, iconType, atLeastDuration, atMostDuration, parentForm, waitForClose); }