* UIMessageBox: 修复一个Bug

This commit is contained in:
Sunny 2024-08-26 10:57:48 +08:00
parent f6a6d75d5f
commit e8ac774e0d
3 changed files with 39 additions and 18 deletions

View File

@ -339,6 +339,8 @@ namespace Sunny.UI
InitEditor(); InitEditor();
} }
public bool ExistsDataPropertyName(string dataPropertyName) => Option != null && Option.ExistsDataPropertyName(dataPropertyName);
public object this[string dataPropertyName] public object this[string dataPropertyName]
{ {
get get

View File

@ -101,6 +101,11 @@ namespace Sunny.UI
public int ValueWidth { get; set; } = 320; 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) public void AddText(string dataPropertyName, string text, string value, bool checkEmpty, bool enabled = true)
{ {
if (Dictionary.ContainsKey(dataPropertyName)) if (Dictionary.ContainsKey(dataPropertyName))

View File

@ -141,20 +141,6 @@ namespace Sunny.UI
return ShowMessageDialog(null, message, title, showCancelButton, style, showMask, defaultButton, delay); 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);
}
}
/// <summary> /// <summary>
/// 确认信息提示框 /// 确认信息提示框
/// </summary> /// </summary>
@ -169,13 +155,14 @@ namespace Sunny.UI
public static bool ShowMessageDialog(Form owner, string message, string title, bool showCancel, public static bool ShowMessageDialog(Form owner, string message, string title, bool showCancel,
UIStyle style, bool showMask = false, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, int delay = 0) UIStyle style, bool showMask = false, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok, int delay = 0)
{ {
bool screenCenter = GetShowOnScreenCenter(showMask, owner);
if (owner == null) if (owner == null)
{ {
using UIMessageForm frm = new UIMessageForm(); using UIMessageForm frm = new UIMessageForm();
frm.ShowMessage(message, title, showCancel, style); frm.ShowMessage(message, title, showCancel, style);
frm.DefaultButton = showCancel ? defaultButton : UIMessageDialogButtons.Ok; frm.DefaultButton = showCancel ? defaultButton : UIMessageDialogButtons.Ok;
frm.Delay = delay; frm.Delay = delay;
return frm.ShowForm(owner, showMask || owner == null, showMask); return frm.ShowForm(owner, screenCenter, showMask);
} }
else else
{ {
@ -185,7 +172,7 @@ namespace Sunny.UI
frm.ShowMessage(message, title, showCancel, style); frm.ShowMessage(message, title, showCancel, style);
frm.DefaultButton = showCancel ? defaultButton : UIMessageDialogButtons.Ok; frm.DefaultButton = showCancel ? defaultButton : UIMessageDialogButtons.Ok;
frm.Delay = delay; frm.Delay = delay;
return frm.ShowForm(owner, showMask || owner == null, showMask); return frm.ShowForm(owner, screenCenter, showMask);
}); });
} }
} }
@ -201,11 +188,12 @@ namespace Sunny.UI
/// <returns>结果</returns> /// <returns>结果</returns>
public static bool ShowMessageDialog2(Form owner, string title, string message, UINotifierType noteType, bool showMask = false, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Cancel, int delay = 0) 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) if (owner == null)
{ {
using UIMessageForm2 frm = new UIMessageForm2(title, message, noteType, defaultButton); using UIMessageForm2 frm = new UIMessageForm2(title, message, noteType, defaultButton);
frm.Delay = delay; frm.Delay = delay;
return frm.ShowForm(owner, showMask || owner == null, showMask); return frm.ShowForm(owner, screenCenter, showMask);
} }
else else
{ {
@ -213,11 +201,20 @@ namespace Sunny.UI
{ {
using UIMessageForm2 frm = new UIMessageForm2(title, message, noteType, defaultButton); using UIMessageForm2 frm = new UIMessageForm2(title, message, noteType, defaultButton);
frm.Delay = delay; 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) internal static bool ShowForm(this UIForm frm, Form owner, bool screenCenter, bool showMask)
{ {
frm.Owner = owner; frm.Owner = owner;
@ -232,6 +229,23 @@ namespace Sunny.UI
else else
return frm.ShowDialog() == DialogResult.OK; 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 public static class UIInputDialog