From e8ac774e0d8350786972d6f04c8611364da4e966 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 26 Aug 2024 10:57:48 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIMessageBox:=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=B8=AABug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Forms/UIEditForm.cs | 2 ++ SunnyUI/Forms/UIEditFormHelper.cs | 5 ++++ SunnyUI/Forms/UIFormHelper.cs | 50 ++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/SunnyUI/Forms/UIEditForm.cs b/SunnyUI/Forms/UIEditForm.cs index e7d51ed1..3a97eb47 100644 --- a/SunnyUI/Forms/UIEditForm.cs +++ b/SunnyUI/Forms/UIEditForm.cs @@ -339,6 +339,8 @@ namespace Sunny.UI InitEditor(); } + public bool ExistsDataPropertyName(string dataPropertyName) => Option != null && Option.ExistsDataPropertyName(dataPropertyName); + public object this[string dataPropertyName] { get diff --git a/SunnyUI/Forms/UIEditFormHelper.cs b/SunnyUI/Forms/UIEditFormHelper.cs index fbc89d0b..0353cabd 100644 --- a/SunnyUI/Forms/UIEditFormHelper.cs +++ b/SunnyUI/Forms/UIEditFormHelper.cs @@ -101,6 +101,11 @@ namespace Sunny.UI public int ValueWidth { get; set; } = 320; + public bool ExistsDataPropertyName(string dataPropertyName) + { + return Dictionary.ContainsKey(dataPropertyName); + } + public void AddText(string dataPropertyName, string text, string value, bool checkEmpty, bool enabled = true) { if (Dictionary.ContainsKey(dataPropertyName)) diff --git a/SunnyUI/Forms/UIFormHelper.cs b/SunnyUI/Forms/UIFormHelper.cs index 87fa2180..b640d76b 100644 --- a/SunnyUI/Forms/UIFormHelper.cs +++ b/SunnyUI/Forms/UIFormHelper.cs @@ -141,20 +141,6 @@ namespace Sunny.UI return ShowMessageDialog(null, message, title, showCancelButton, style, showMask, defaultButton, delay); } - internal static Point GetLocation(this Size size, Form owner, bool screenCenter) - { - Rectangle screen = Screen.GetBounds(SystemEx.GetCursorPos()); - if (screenCenter) - { - return new Point(screen.Left + screen.Width / 2 - size.Width / 2, screen.Top + screen.Height / 2 - size.Height / 2); - } - else - { - if (owner is UIPage) owner = owner.ParentForm; - return new Point(owner.Left + owner.Width / 2 - size.Width / 2, owner.Top + owner.Height / 2 - size.Height / 2); - } - } - /// /// 确认信息提示框 /// @@ -169,13 +155,14 @@ namespace Sunny.UI public static bool ShowMessageDialog(Form owner, string message, string title, bool showCancel, UIStyle style, bool showMask = false, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, int delay = 0) { + bool screenCenter = GetShowOnScreenCenter(showMask, owner); if (owner == null) { using UIMessageForm frm = new UIMessageForm(); frm.ShowMessage(message, title, showCancel, style); frm.DefaultButton = showCancel ? defaultButton : UIMessageDialogButtons.Ok; frm.Delay = delay; - return frm.ShowForm(owner, showMask || owner == null, showMask); + return frm.ShowForm(owner, screenCenter, showMask); } else { @@ -185,7 +172,7 @@ namespace Sunny.UI frm.ShowMessage(message, title, showCancel, style); frm.DefaultButton = showCancel ? defaultButton : UIMessageDialogButtons.Ok; frm.Delay = delay; - return frm.ShowForm(owner, showMask || owner == null, showMask); + return frm.ShowForm(owner, screenCenter, showMask); }); } } @@ -201,11 +188,12 @@ namespace Sunny.UI /// 结果 public static bool ShowMessageDialog2(Form owner, string title, string message, UINotifierType noteType, bool showMask = false, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Cancel, int delay = 0) { + bool screenCenter = GetShowOnScreenCenter(showMask, owner); if (owner == null) { using UIMessageForm2 frm = new UIMessageForm2(title, message, noteType, defaultButton); frm.Delay = delay; - return frm.ShowForm(owner, showMask || owner == null, showMask); + return frm.ShowForm(owner, screenCenter, showMask); } else { @@ -213,11 +201,20 @@ namespace Sunny.UI { using UIMessageForm2 frm = new UIMessageForm2(title, message, noteType, defaultButton); frm.Delay = delay; - return frm.ShowForm(owner, showMask || owner == null, showMask); + return frm.ShowForm(owner, screenCenter, showMask); }); } } + private static bool GetShowOnScreenCenter(bool showMask, Form owner) + { + if (showMask) return true; + if (owner == null) return true; + if (owner.TopLevel) return false; + if (owner.ParentForm == null) return true; + return false; + } + internal static bool ShowForm(this UIForm frm, Form owner, bool screenCenter, bool showMask) { frm.Owner = owner; @@ -232,6 +229,23 @@ namespace Sunny.UI else return frm.ShowDialog() == DialogResult.OK; } + + private static Point GetLocation(this Size size, Form owner, bool screenCenter) + { + Rectangle screen = Screen.GetBounds(SystemEx.GetCursorPos()); + if (screenCenter || owner == null) + { + return new Point(screen.Left + screen.Width / 2 - size.Width / 2, screen.Top + screen.Height / 2 - size.Height / 2); + } + else + { + Form form = owner.TopLevel ? owner : owner.ParentForm; + if (form == null) + return new Point(screen.Left + screen.Width / 2 - size.Width / 2, screen.Top + screen.Height / 2 - size.Height / 2); + else + return new Point(form.Left + form.Width / 2 - size.Width / 2, form.Top + form.Height / 2 - size.Height / 2); + } + } } public static class UIInputDialog