diff --git a/SunnyUI/Forms/UIFormHelper.cs b/SunnyUI/Forms/UIFormHelper.cs index fe9d64d2..b2ab8656 100644 --- a/SunnyUI/Forms/UIFormHelper.cs +++ b/SunnyUI/Forms/UIFormHelper.cs @@ -26,6 +26,7 @@ * 2023-07-27: V3.4.1 提问弹窗增加默认是确认或者取消按钮的选择 * 2024-04-22: V3.6.5 重构,所有弹窗调整为窗体的扩展方法,使用时加上this. * 2024-04-22: V3.6.5 输入弹窗前增加Show前缀 + * 2024-04-27: V3.6.5 提示框增加延时关闭 ******************************************************************************/ using System; @@ -125,8 +126,10 @@ namespace Sunny.UI /// 主题 /// 显示遮罩层 /// 置顶 + /// 默认按钮 + /// 消息停留时长(ms)。默认1秒 /// 结果 - public static bool ShowMessageDialog(string message, string title, bool showCancelButton, UIStyle style, bool showMask = true, bool topMost = true, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok) + public static bool ShowMessageDialog(string message, string title, bool showCancelButton, UIStyle style, bool showMask = true, bool topMost = true, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, int delay = 0) { Point pt = SystemEx.GetCursorPos(); Rectangle screen = Screen.GetBounds(pt); @@ -136,6 +139,7 @@ namespace Sunny.UI frm.ShowMessage(message, title, showCancelButton, style); frm.ShowInTaskbar = false; frm.TopMost = topMost; + frm.Delay = delay; frm.Render(); if (showMask) @@ -475,9 +479,9 @@ namespace Sunny.UI /// /// 信息 /// 显示遮罩层 - public static void ShowSuccessDialog(this Form form, string msg, bool showMask = false) + public static void ShowSuccessDialog(this Form form, string msg, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, UILocalize.SuccessTitle, false, UIStyle.Green, showMask, true); + form.ShowSuccessDialog(UILocalize.SuccessTitle, msg, UIStyle.Green, showMask, delay); } /// @@ -487,9 +491,9 @@ namespace Sunny.UI /// 信息 /// 主题 /// 显示遮罩层 - public static void ShowSuccessDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Green, bool showMask = false) + public static void ShowSuccessDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Green, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true); + UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true, UIMessageDialogButtons.Ok, delay); } /// @@ -497,9 +501,9 @@ namespace Sunny.UI /// /// 信息 /// 显示遮罩层 - public static void ShowInfoDialog(this Form form, string msg, bool showMask = false) + public static void ShowInfoDialog(this Form form, string msg, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, UILocalize.InfoTitle, false, UIStyle.Gray, showMask, true); + form.ShowInfoDialog(UILocalize.SuccessTitle, msg, UIStyle.Gray, showMask, delay); } /// @@ -509,9 +513,9 @@ namespace Sunny.UI /// 信息 /// 主题 /// 显示遮罩层 - public static void ShowInfoDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Gray, bool showMask = false) + public static void ShowInfoDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Gray, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true); + UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true, UIMessageDialogButtons.Ok, delay); } /// @@ -519,9 +523,9 @@ namespace Sunny.UI /// /// 信息 /// 显示遮罩层 - public static void ShowWarningDialog(this Form form, string msg, bool showMask = false) + public static void ShowWarningDialog(this Form form, string msg, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, UILocalize.WarningTitle, false, UIStyle.Orange, showMask, true); + form.ShowWarningDialog(UILocalize.SuccessTitle, msg, UIStyle.Orange, showMask, delay); } /// @@ -531,9 +535,9 @@ namespace Sunny.UI /// 信息 /// 主题 /// 显示遮罩层 - public static void ShowWarningDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Orange, bool showMask = false) + public static void ShowWarningDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Orange, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true); + UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true, UIMessageDialogButtons.Ok, delay); } /// @@ -541,9 +545,9 @@ namespace Sunny.UI /// /// 信息 /// 显示遮罩层 - public static void ShowErrorDialog(this Form form, string msg, bool showMask = false) + public static void ShowErrorDialog(this Form form, string msg, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, UILocalize.ErrorTitle, false, UIStyle.Red, showMask, true); + form.ShowErrorDialog(UILocalize.SuccessTitle, msg, UIStyle.Red, showMask, delay); } /// @@ -553,9 +557,9 @@ namespace Sunny.UI /// 信息 /// 主题 /// 显示遮罩层 - public static void ShowErrorDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Red, bool showMask = false) + public static void ShowErrorDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Red, bool showMask = false, int delay = 0) { - UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true); + UIMessageBox.ShowMessageDialog(msg, title, false, style, showMask, true, UIMessageDialogButtons.Ok, delay); } /// diff --git a/SunnyUI/Forms/UIMessageForm.Designer.cs b/SunnyUI/Forms/UIMessageForm.Designer.cs index 2990bc27..bd70dfe7 100644 --- a/SunnyUI/Forms/UIMessageForm.Designer.cs +++ b/SunnyUI/Forms/UIMessageForm.Designer.cs @@ -28,9 +28,11 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); btnCancel = new UIButton(); btnOK = new UIButton(); lbMsg = new UIRichTextBox(); + timer1 = new System.Windows.Forms.Timer(components); SuspendLayout(); // // btnCancel @@ -78,12 +80,18 @@ lbMsg.RadiusSides = UICornerRadiusSides.None; lbMsg.ReadOnly = true; lbMsg.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; + lbMsg.ScrollBarStyleInherited = false; lbMsg.ShowText = false; lbMsg.Size = new System.Drawing.Size(422, 158); lbMsg.Style = UIStyle.Custom; lbMsg.TabIndex = 7; lbMsg.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; // + // timer1 + // + timer1.Interval = 1000; + timer1.Tick += timer1_Tick; + // // UIMessageForm // AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -108,5 +116,6 @@ private UIButton btnCancel; private UIButton btnOK; private UIRichTextBox lbMsg; + private System.Windows.Forms.Timer timer1; } } \ No newline at end of file diff --git a/SunnyUI/Forms/UIMessageForm.cs b/SunnyUI/Forms/UIMessageForm.cs index 447edf52..633f8fd7 100644 --- a/SunnyUI/Forms/UIMessageForm.cs +++ b/SunnyUI/Forms/UIMessageForm.cs @@ -183,6 +183,34 @@ namespace Sunny.UI else btnCancel.Focus(); } + + if (delay <= 0) return; + if (text == "") text = Text; + Text = text + " [" + delay + "]"; + } + + int delay = 0; + + public int Delay + { + set + { + if (value > 0) + { + delay = value / 1000; + timer1.Start(); + } + } + } + + string text = ""; + + private void timer1_Tick(object sender, EventArgs e) + { + delay--; + Text = text + " [" + delay + "]"; + + if (delay <= 0) Close(); } } } \ No newline at end of file diff --git a/SunnyUI/Forms/UIMessageForm.resx b/SunnyUI/Forms/UIMessageForm.resx index af32865e..80e1e44e 100644 --- a/SunnyUI/Forms/UIMessageForm.resx +++ b/SunnyUI/Forms/UIMessageForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file