* UIFormHelper: 提示框增加延时关闭

This commit is contained in:
Sunny 2024-04-27 17:27:09 +08:00
parent aac4fb6382
commit 8bdaac1ea8
4 changed files with 61 additions and 17 deletions

View File

@ -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
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
/// <param name="topMost">置顶</param>
/// <param name="defaultButton">默认按钮</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <returns>结果</returns>
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
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -487,9 +491,9 @@ namespace Sunny.UI
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -497,9 +501,9 @@ namespace Sunny.UI
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -509,9 +513,9 @@ namespace Sunny.UI
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -519,9 +523,9 @@ namespace Sunny.UI
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -531,9 +535,9 @@ namespace Sunny.UI
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -541,9 +545,9 @@ namespace Sunny.UI
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>
@ -553,9 +557,9 @@ namespace Sunny.UI
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
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);
}
/// <summary>

View File

@ -28,9 +28,11 @@
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>