* UIFormHelper: 提示框增加延时关闭
This commit is contained in:
parent
aac4fb6382
commit
8bdaac1ea8
@ -26,6 +26,7 @@
|
|||||||
* 2023-07-27: V3.4.1 提问弹窗增加默认是确认或者取消按钮的选择
|
* 2023-07-27: V3.4.1 提问弹窗增加默认是确认或者取消按钮的选择
|
||||||
* 2024-04-22: V3.6.5 重构,所有弹窗调整为窗体的扩展方法,使用时加上this.
|
* 2024-04-22: V3.6.5 重构,所有弹窗调整为窗体的扩展方法,使用时加上this.
|
||||||
* 2024-04-22: V3.6.5 输入弹窗前增加Show前缀
|
* 2024-04-22: V3.6.5 输入弹窗前增加Show前缀
|
||||||
|
* 2024-04-27: V3.6.5 提示框增加延时关闭
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -125,8 +126,10 @@ namespace Sunny.UI
|
|||||||
/// <param name="style">主题</param>
|
/// <param name="style">主题</param>
|
||||||
/// <param name="showMask">显示遮罩层</param>
|
/// <param name="showMask">显示遮罩层</param>
|
||||||
/// <param name="topMost">置顶</param>
|
/// <param name="topMost">置顶</param>
|
||||||
|
/// <param name="defaultButton">默认按钮</param>
|
||||||
|
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
|
||||||
/// <returns>结果</returns>
|
/// <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();
|
Point pt = SystemEx.GetCursorPos();
|
||||||
Rectangle screen = Screen.GetBounds(pt);
|
Rectangle screen = Screen.GetBounds(pt);
|
||||||
@ -136,6 +139,7 @@ namespace Sunny.UI
|
|||||||
frm.ShowMessage(message, title, showCancelButton, style);
|
frm.ShowMessage(message, title, showCancelButton, style);
|
||||||
frm.ShowInTaskbar = false;
|
frm.ShowInTaskbar = false;
|
||||||
frm.TopMost = topMost;
|
frm.TopMost = topMost;
|
||||||
|
frm.Delay = delay;
|
||||||
frm.Render();
|
frm.Render();
|
||||||
|
|
||||||
if (showMask)
|
if (showMask)
|
||||||
@ -475,9 +479,9 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -487,9 +491,9 @@ namespace Sunny.UI
|
|||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="style">主题</param>
|
/// <param name="style">主题</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -497,9 +501,9 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -509,9 +513,9 @@ namespace Sunny.UI
|
|||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="style">主题</param>
|
/// <param name="style">主题</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -519,9 +523,9 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -531,9 +535,9 @@ namespace Sunny.UI
|
|||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="style">主题</param>
|
/// <param name="style">主题</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -541,9 +545,9 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
@ -553,9 +557,9 @@ namespace Sunny.UI
|
|||||||
/// <param name="msg">信息</param>
|
/// <param name="msg">信息</param>
|
||||||
/// <param name="style">主题</param>
|
/// <param name="style">主题</param>
|
||||||
/// <param name="showMask">显示遮罩层</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>
|
/// <summary>
|
||||||
|
9
SunnyUI/Forms/UIMessageForm.Designer.cs
generated
9
SunnyUI/Forms/UIMessageForm.Designer.cs
generated
@ -28,9 +28,11 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
btnCancel = new UIButton();
|
btnCancel = new UIButton();
|
||||||
btnOK = new UIButton();
|
btnOK = new UIButton();
|
||||||
lbMsg = new UIRichTextBox();
|
lbMsg = new UIRichTextBox();
|
||||||
|
timer1 = new System.Windows.Forms.Timer(components);
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// btnCancel
|
// btnCancel
|
||||||
@ -78,12 +80,18 @@
|
|||||||
lbMsg.RadiusSides = UICornerRadiusSides.None;
|
lbMsg.RadiusSides = UICornerRadiusSides.None;
|
||||||
lbMsg.ReadOnly = true;
|
lbMsg.ReadOnly = true;
|
||||||
lbMsg.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None;
|
lbMsg.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None;
|
||||||
|
lbMsg.ScrollBarStyleInherited = false;
|
||||||
lbMsg.ShowText = false;
|
lbMsg.ShowText = false;
|
||||||
lbMsg.Size = new System.Drawing.Size(422, 158);
|
lbMsg.Size = new System.Drawing.Size(422, 158);
|
||||||
lbMsg.Style = UIStyle.Custom;
|
lbMsg.Style = UIStyle.Custom;
|
||||||
lbMsg.TabIndex = 7;
|
lbMsg.TabIndex = 7;
|
||||||
lbMsg.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
|
lbMsg.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
|
// timer1
|
||||||
|
//
|
||||||
|
timer1.Interval = 1000;
|
||||||
|
timer1.Tick += timer1_Tick;
|
||||||
|
//
|
||||||
// UIMessageForm
|
// UIMessageForm
|
||||||
//
|
//
|
||||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||||
@ -108,5 +116,6 @@
|
|||||||
private UIButton btnCancel;
|
private UIButton btnCancel;
|
||||||
private UIButton btnOK;
|
private UIButton btnOK;
|
||||||
private UIRichTextBox lbMsg;
|
private UIRichTextBox lbMsg;
|
||||||
|
private System.Windows.Forms.Timer timer1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -183,6 +183,34 @@ namespace Sunny.UI
|
|||||||
else
|
else
|
||||||
btnCancel.Focus();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -117,4 +117,7 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</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>
|
</root>
|
Loading…
x
Reference in New Issue
Block a user