diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index 5ba4d923..f2a3e0fd 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -1971,9 +1971,9 @@ namespace Sunny.UI /// 信息 /// 显示遮罩层 /// 结果 - public bool ShowAskDialog(string msg, bool showMask = false) + public bool ShowAskDialog(string msg, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, bool showMask = false) { - return UIMessageDialog.ShowMessageDialog(msg, UILocalize.AskTitle, true, UIStyle.Blue, showMask, true); + return UIMessageDialog.ShowMessageDialog(msg, UILocalize.AskTitle, true, UIStyle.Blue, showMask, true, defaultButton); } /// @@ -2032,9 +2032,9 @@ namespace Sunny.UI /// 主题 /// 显示遮罩层 /// 结果 - public bool ShowAskDialog(string title, string msg, UIStyle style = UIStyle.Blue, bool showMask = false) + public bool ShowAskDialog(string title, string msg, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, UIStyle style = UIStyle.Blue, bool showMask = false) { - return UIMessageDialog.ShowMessageDialog(msg, title, true, style, showMask, true); + return UIMessageDialog.ShowMessageDialog(msg, title, true, style, showMask, true, defaultButton); } /// diff --git a/SunnyUI/Forms/UIFormHelper.cs b/SunnyUI/Forms/UIFormHelper.cs index 798674c1..a29d556d 100644 --- a/SunnyUI/Forms/UIFormHelper.cs +++ b/SunnyUI/Forms/UIFormHelper.cs @@ -23,6 +23,7 @@ * 2021-12-13: V3.0.9 增加全屏遮罩,Form的ShowDialogWithMask()扩展方法 * 2022-07-17: V3.2.1 解决ShowNotifier打开多个,全部关闭时出错的问题 * 2023-07-27: V3.4.1 默认提示弹窗TopMost为true + * 2023-07-27: V3.4.1 提问弹窗增加可选择默认是确认或者取消按钮的选择 ******************************************************************************/ using System; @@ -86,52 +87,7 @@ namespace Sunny.UI /// 主题 public static void ShowSuccessDialog(this Form form, string msg, UIStyle style = UIStyle.Green) { - form.ShowMessageDialog(msg, UILocalize.SuccessTitle, false, style); - } - - /// - /// 信息提示框 - /// - /// 窗体 - /// 信息 - /// 主题 - public static void ShowInfoDialog(this Form form, string msg, UIStyle style = UIStyle.Gray) - { - form.ShowMessageDialog(msg, UILocalize.InfoTitle, false, style); - } - - /// - /// 警告信息提示框 - /// - /// 窗体 - /// 信息 - /// 主题 - public static void ShowWarningDialog(this Form form, string msg, UIStyle style = UIStyle.Orange) - { - form.ShowMessageDialog(msg, UILocalize.WarningTitle, false, style); - } - - /// - /// 错误信息提示框 - /// - /// 窗体 - /// 信息 - /// 主题 - public static void ShowErrorDialog(this Form form, string msg, UIStyle style = UIStyle.Red) - { - form.ShowMessageDialog(msg, UILocalize.ErrorTitle, false, style); - } - - /// - /// 确认信息提示框 - /// - /// 窗体 - /// 信息 - /// - /// 结果 - public static bool ShowAskDialog(this Form form, string msg, UIStyle style = UIStyle.Blue) - { - return form.ShowMessageDialog(msg, UILocalize.AskTitle, true, style); + form.ShowSuccessDialog(UILocalize.SuccessTitle, msg, style); } /// @@ -146,6 +102,17 @@ namespace Sunny.UI form.ShowMessageDialog(msg, title, false, style); } + /// + /// 信息提示框 + /// + /// 窗体 + /// 信息 + /// 主题 + public static void ShowInfoDialog(this Form form, string msg, UIStyle style = UIStyle.Gray) + { + form.ShowInfoDialog(UILocalize.InfoTitle, msg, style); + } + /// /// 信息提示框 /// @@ -158,6 +125,17 @@ namespace Sunny.UI form.ShowMessageDialog(msg, title, false, style); } + /// + /// 警告信息提示框 + /// + /// 窗体 + /// 信息 + /// 主题 + public static void ShowWarningDialog(this Form form, string msg, UIStyle style = UIStyle.Orange) + { + form.ShowWarningDialog(UILocalize.WarningTitle, msg, style); + } + /// /// 警告信息提示框 /// @@ -170,6 +148,17 @@ namespace Sunny.UI form.ShowMessageDialog(msg, title, false, style); } + /// + /// 错误信息提示框 + /// + /// 窗体 + /// 信息 + /// 主题 + public static void ShowErrorDialog(this Form form, string msg, UIStyle style = UIStyle.Red) + { + form.ShowErrorDialog(UILocalize.ErrorTitle, msg, style); + } + /// /// 错误信息提示框 /// @@ -182,6 +171,18 @@ namespace Sunny.UI form.ShowMessageDialog(msg, title, false, style); } + /// + /// 确认信息提示框 + /// + /// 窗体 + /// 信息 + /// + /// 结果 + public static bool ShowAskDialog(this Form form, string msg, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, UIStyle style = UIStyle.Blue) + { + return form.ShowAskDialog(UILocalize.AskTitle, msg, defaultButton, style); + } + /// /// 确认信息提示框 /// @@ -190,7 +191,7 @@ namespace Sunny.UI /// 信息 /// /// 结果 - public static bool ShowAskDialog(this Form form, string title, string msg, UIStyle style = UIStyle.Blue) + public static bool ShowAskDialog(this Form form, string title, string msg, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, UIStyle style = UIStyle.Blue) { return form.ShowMessageDialog(msg, title, true, style); } @@ -216,11 +217,21 @@ namespace Sunny.UI /// 显示遮罩层 /// 置顶 /// 结果 - public static bool ShowMessageDialog(string message, string title, bool showCancelButton, UIStyle style, bool showMask = true, bool topMost = true) + public static bool ShowMessageDialog(string message, string title, bool showCancelButton, UIStyle style, bool showMask = true, bool topMost = true, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok) { Point pt = SystemEx.GetCursorPos(); Rectangle screen = Screen.GetBounds(pt); UIMessageForm frm = new UIMessageForm(); + + if (showCancelButton) + { + frm.DefaultButton = defaultButton; + } + else + { + frm.DefaultButton = UIMessageDialogButtons.Ok; + } + frm.StartPosition = FormStartPosition.CenterScreen; frm.ShowMessage(message, title, showCancelButton, style); frm.ShowInTaskbar = false; @@ -237,6 +248,12 @@ namespace Sunny.UI } } + public enum UIMessageDialogButtons + { + Ok, + Cancel + } + public static class UIMessageBox { public static void Show(string text, bool showMask = true, bool topMost = true) diff --git a/SunnyUI/Forms/UIMessageForm.Designer.cs b/SunnyUI/Forms/UIMessageForm.Designer.cs index 98851e97..ba003e0a 100644 --- a/SunnyUI/Forms/UIMessageForm.Designer.cs +++ b/SunnyUI/Forms/UIMessageForm.Designer.cs @@ -28,85 +28,82 @@ /// private void InitializeComponent() { - this.btnCancel = new Sunny.UI.UIButton(); - this.btnOK = new Sunny.UI.UIButton(); - this.lbMsg = new Sunny.UI.UIRichTextBox(); - this.SuspendLayout(); + btnCancel = new UIButton(); + btnOK = new UIButton(); + lbMsg = new UIRichTextBox(); + SuspendLayout(); // // btnCancel // - this.btnCancel.BackColor = System.Drawing.Color.Transparent; - this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand; - this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 12F); - this.btnCancel.Location = new System.Drawing.Point(224, 220); - this.btnCancel.Margin = new System.Windows.Forms.Padding(0); - this.btnCancel.MinimumSize = new System.Drawing.Size(1, 1); - this.btnCancel.Name = "btnCancel"; - this.btnCancel.Size = new System.Drawing.Size(224, 48); - this.btnCancel.TabIndex = 6; - this.btnCancel.Text = "取消"; - this.btnCancel.TipsFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.btnCancel.TipsText = null; - this.btnCancel.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); - this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); - this.btnCancel.MouseEnter += new System.EventHandler(this.btnOK_MouseEnter); - this.btnCancel.MouseLeave += new System.EventHandler(this.btnOK_MouseLeave); + btnCancel.BackColor = System.Drawing.Color.Transparent; + btnCancel.Cursor = System.Windows.Forms.Cursors.Hand; + btnCancel.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + btnCancel.Location = new System.Drawing.Point(224, 220); + btnCancel.Margin = new System.Windows.Forms.Padding(0); + btnCancel.MinimumSize = new System.Drawing.Size(1, 1); + btnCancel.Name = "btnCancel"; + btnCancel.Size = new System.Drawing.Size(224, 48); + btnCancel.TabIndex = 6; + btnCancel.Text = "取消"; + btnCancel.TipsFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + btnCancel.TipsText = null; + btnCancel.Click += btnCancel_Click; + btnCancel.MouseEnter += btnOK_MouseEnter; + btnCancel.MouseLeave += btnOK_MouseLeave; // // btnOK // - this.btnOK.BackColor = System.Drawing.Color.Transparent; - this.btnOK.Cursor = System.Windows.Forms.Cursors.Hand; - this.btnOK.Font = new System.Drawing.Font("微软雅黑", 12F); - this.btnOK.Location = new System.Drawing.Point(2, 220); - this.btnOK.Margin = new System.Windows.Forms.Padding(0); - this.btnOK.MinimumSize = new System.Drawing.Size(1, 1); - this.btnOK.Name = "btnOK"; - this.btnOK.Size = new System.Drawing.Size(223, 48); - this.btnOK.TabIndex = 5; - this.btnOK.Text = "确定"; - this.btnOK.TipsFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.btnOK.TipsText = null; - this.btnOK.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); - this.btnOK.Click += new System.EventHandler(this.btnOK_Click); - this.btnOK.MouseEnter += new System.EventHandler(this.btnOK_MouseEnter); - this.btnOK.MouseLeave += new System.EventHandler(this.btnOK_MouseLeave); + btnOK.BackColor = System.Drawing.Color.Transparent; + btnOK.Cursor = System.Windows.Forms.Cursors.Hand; + btnOK.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + btnOK.Location = new System.Drawing.Point(2, 220); + btnOK.Margin = new System.Windows.Forms.Padding(0); + btnOK.MinimumSize = new System.Drawing.Size(1, 1); + btnOK.Name = "btnOK"; + btnOK.Size = new System.Drawing.Size(223, 48); + btnOK.TabIndex = 5; + btnOK.Text = "确定"; + btnOK.TipsFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + btnOK.TipsText = null; + btnOK.Click += btnOK_Click; + btnOK.MouseEnter += btnOK_MouseEnter; + btnOK.MouseLeave += btnOK_MouseLeave; // // lbMsg // - this.lbMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255))))); - this.lbMsg.FillColor = System.Drawing.Color.White; - this.lbMsg.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lbMsg.Location = new System.Drawing.Point(14, 50); - this.lbMsg.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.lbMsg.MinimumSize = new System.Drawing.Size(1, 1); - this.lbMsg.Name = "lbMsg"; - this.lbMsg.Padding = new System.Windows.Forms.Padding(2); - this.lbMsg.RadiusSides = Sunny.UI.UICornerRadiusSides.None; - this.lbMsg.ReadOnly = true; - this.lbMsg.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; - this.lbMsg.ShowText = false; - this.lbMsg.Size = new System.Drawing.Size(422, 158); - this.lbMsg.TabIndex = 7; - this.lbMsg.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; - this.lbMsg.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); + lbMsg.BackColor = System.Drawing.Color.FromArgb(235, 243, 255); + lbMsg.FillColor = System.Drawing.Color.White; + lbMsg.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + lbMsg.Location = new System.Drawing.Point(14, 50); + lbMsg.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + lbMsg.MinimumSize = new System.Drawing.Size(1, 1); + lbMsg.Name = "lbMsg"; + lbMsg.Padding = new System.Windows.Forms.Padding(2); + lbMsg.RadiusSides = UICornerRadiusSides.None; + lbMsg.ReadOnly = true; + lbMsg.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; + lbMsg.ShowText = false; + lbMsg.Size = new System.Drawing.Size(422, 158); + lbMsg.TabIndex = 7; + lbMsg.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; // // UIMessageForm // - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.ClientSize = new System.Drawing.Size(450, 270); - this.Controls.Add(this.lbMsg); - this.Controls.Add(this.btnCancel); - this.Controls.Add(this.btnOK); - this.EscClose = true; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "UIMessageForm"; - this.Padding = new System.Windows.Forms.Padding(1, 35, 1, 3); - this.ShowInTaskbar = false; - this.Text = "UIMsgBox"; - this.ZoomScaleRect = new System.Drawing.Rectangle(15, 15, 450, 270); - this.ResumeLayout(false); - + AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + ClientSize = new System.Drawing.Size(450, 270); + Controls.Add(lbMsg); + Controls.Add(btnCancel); + Controls.Add(btnOK); + EscClose = true; + MaximizeBox = false; + MinimizeBox = false; + Name = "UIMessageForm"; + Padding = new System.Windows.Forms.Padding(1, 35, 1, 3); + ShowInTaskbar = false; + Text = "UIMsgBox"; + ZoomScaleRect = new System.Drawing.Rectangle(15, 15, 450, 270); + Shown += UIMessageForm_Shown; + ResumeLayout(false); } #endregion diff --git a/SunnyUI/Forms/UIMessageForm.cs b/SunnyUI/Forms/UIMessageForm.cs index 4c01a8f4..c990c68e 100644 --- a/SunnyUI/Forms/UIMessageForm.cs +++ b/SunnyUI/Forms/UIMessageForm.cs @@ -100,7 +100,10 @@ namespace Sunny.UI protected override void DoEnter() { base.DoEnter(); - btnOK_Click(null, null); + if (!ShowCancel) + { + btnOK_Click(null, null); + } } private void btnOK_Click(object sender, EventArgs e) @@ -125,13 +128,6 @@ namespace Sunny.UI { base.SetStyleColor(uiColor); - if (btnOK != null) - { - btnOK.FillColor = BackColor; - btnOK.RectColor = Color.FromArgb(36, uiColor.ButtonRectColor); - btnOK.ForeColor = uiColor.LabelForeColor; - } - if (btnCancel != null) { btnCancel.FillColor = BackColor; @@ -139,6 +135,13 @@ namespace Sunny.UI btnCancel.ForeColor = uiColor.LabelForeColor; } + if (btnOK != null) + { + btnOK.FillColor = BackColor; + btnOK.RectColor = Color.FromArgb(36, uiColor.ButtonRectColor); + btnOK.ForeColor = uiColor.LabelForeColor; + } + if (lbMsg != null) { lbMsg.ForeColor = uiColor.LabelForeColor; @@ -149,6 +152,8 @@ namespace Sunny.UI } } + public UIMessageDialogButtons DefaultButton { get; set; } = UIMessageDialogButtons.Ok; + private void btnOK_MouseEnter(object sender, EventArgs e) { //((UIButton)sender).RadiusSides = UICornerRadiusSides.All; @@ -175,5 +180,17 @@ namespace Sunny.UI //btnOK.ShowFocusLine = btnCancel.ShowFocusLine = showCancel; btnOK.ShowFocusColor = btnCancel.ShowFocusColor = showCancel; } + + private void UIMessageForm_Shown(object sender, EventArgs e) + { + if (!ShowCancel || DefaultButton == UIMessageDialogButtons.Ok) + { + btnOK.Focus(); + } + else + { + btnCancel.Focus(); + } + } } } \ No newline at end of file diff --git a/SunnyUI/Forms/UIMessageForm.resx b/SunnyUI/Forms/UIMessageForm.resx index 1af7de15..a395bffc 100644 --- a/SunnyUI/Forms/UIMessageForm.resx +++ b/SunnyUI/Forms/UIMessageForm.resx @@ -1,24 +1,24 @@  - diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index a19ffb5f..874725ff 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -1233,9 +1233,9 @@ namespace Sunny.UI /// 信息 /// 显示遮罩层 /// 结果 - public bool ShowAskDialog(string msg, bool showMask = false) + public bool ShowAskDialog(string msg, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, bool showMask = false) { - return UIMessageDialog.ShowMessageDialog(msg, UILocalize.AskTitle, true, UIStyle.Blue, showMask, true); + return UIMessageDialog.ShowMessageDialog(msg, UILocalize.AskTitle, true, UIStyle.Blue, showMask, true, defaultButton); } /// @@ -1294,9 +1294,9 @@ namespace Sunny.UI /// 主题 /// 显示遮罩层 /// 结果 - public bool ShowAskDialog(string title, string msg, UIStyle style = UIStyle.Blue, bool showMask = false) + public bool ShowAskDialog(string title, string msg, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, UIStyle style = UIStyle.Blue, bool showMask = false) { - return UIMessageDialog.ShowMessageDialog(msg, title, true, style, showMask, true); + return UIMessageDialog.ShowMessageDialog(msg, title, true, style, showMask, true, defaultButton); } ///