From bc66440c9742843f5f613beb033443fd107ef03d Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 26 Mar 2023 22:06:43 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E5=86=85=E7=BD=AE=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=AE=B9=E5=99=A8=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E4=B8=8B=E6=8B=89=E6=A1=86=E7=9A=84=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UControl.cs | 12 ++++++++++++ SunnyUI/Controls/UIComboBox.cs | 2 +- SunnyUI/Controls/UIGlobal.cs | 5 +++++ SunnyUI/Controls/UINumPadTextBox.cs | 2 +- SunnyUI/Controls/UIUserControl.cs | 6 ++++++ SunnyUI/Forms/UIForm.cs | 8 +++++++- SunnyUI/Frames/UIPage.cs | 6 ++++++ SunnyUI/Style/UIStyle.cs | 4 ++-- 8 files changed, 40 insertions(+), 5 deletions(-) diff --git a/SunnyUI/Common/UControl.cs b/SunnyUI/Common/UControl.cs index 32dc681c..0b31fe5a 100644 --- a/SunnyUI/Common/UControl.cs +++ b/SunnyUI/Common/UControl.cs @@ -386,6 +386,18 @@ namespace Sunny.UI return list; } + internal static void HideComboDropDown(this Control ctrl) + { + var ctrls = ctrl.RootForm().GetInterfaceControls("IHideDropDown", true); + foreach (var control in ctrls) + { + if (control is IHideDropDown item) + { + item.HideDropDown(); + } + } + } + /// /// 查找包含接口名称的控件列表 /// diff --git a/SunnyUI/Controls/UIComboBox.cs b/SunnyUI/Controls/UIComboBox.cs index bd749a38..f6639fb7 100644 --- a/SunnyUI/Controls/UIComboBox.cs +++ b/SunnyUI/Controls/UIComboBox.cs @@ -53,7 +53,7 @@ namespace Sunny.UI [DefaultEvent("SelectedIndexChanged")] [ToolboxItem(true)] [LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")] - public sealed partial class UIComboBox : UIDropControl, IToolTip + public sealed partial class UIComboBox : UIDropControl, IToolTip, IHideDropDown { /// /// 构造函数 diff --git a/SunnyUI/Controls/UIGlobal.cs b/SunnyUI/Controls/UIGlobal.cs index f15138da..871860cc 100644 --- a/SunnyUI/Controls/UIGlobal.cs +++ b/SunnyUI/Controls/UIGlobal.cs @@ -40,6 +40,11 @@ namespace Sunny.UI public const int EditorMaxHeight = 60; } + public interface IHideDropDown + { + public void HideDropDown(); + } + public class UIDateTimeArgs : EventArgs { public DateTime DateTime { get; set; } diff --git a/SunnyUI/Controls/UINumPadTextBox.cs b/SunnyUI/Controls/UINumPadTextBox.cs index 434176be..e9d968a7 100644 --- a/SunnyUI/Controls/UINumPadTextBox.cs +++ b/SunnyUI/Controls/UINumPadTextBox.cs @@ -29,7 +29,7 @@ namespace Sunny.UI { [ToolboxItem(true)] [DefaultEvent("ValueChanged")] - public class UINumPadTextBox : UIDropControl, IToolTip + public class UINumPadTextBox : UIDropControl, IToolTip, IHideDropDown { public UINumPadTextBox() { diff --git a/SunnyUI/Controls/UIUserControl.cs b/SunnyUI/Controls/UIUserControl.cs index 362cb46c..987b1262 100644 --- a/SunnyUI/Controls/UIUserControl.cs +++ b/SunnyUI/Controls/UIUserControl.cs @@ -50,6 +50,12 @@ namespace Sunny.UI SetStyleFlags(true, false); } + protected override void OnClick(EventArgs e) + { + base.OnClick(e); + this.HideComboDropDown(); + } + [Browsable(false)] public bool Disabled => !Enabled; diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index 66bc770a..a92b5db5 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -213,7 +213,7 @@ namespace Sunny.UI public void Translate() { - List controls = this.GetTranslateControls("ITranslate"); + List controls = this.GetInterfaceControls("ITranslate"); foreach (var control in controls) { if (control is ITranslate item) @@ -685,6 +685,12 @@ namespace Sunny.UI } } + protected override void OnClick(EventArgs e) + { + base.OnClick(e); + this.HideComboDropDown(); + } + protected override void OnMouseClick(MouseEventArgs e) { if (FormBorderStyle == FormBorderStyle.None && ShowTitle) diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index 751c59f1..38c236fc 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -110,6 +110,12 @@ namespace Sunny.UI base.SizeGripStyle = SizeGripStyle.Hide; } + protected override void OnClick(EventArgs e) + { + base.OnClick(e); + this.HideComboDropDown(); + } + public event PageDeselectingEventHandler PageDeselecting; internal bool OnPageDeselecting() diff --git a/SunnyUI/Style/UIStyle.cs b/SunnyUI/Style/UIStyle.cs index af4b4c45..453b9ff6 100644 --- a/SunnyUI/Style/UIStyle.cs +++ b/SunnyUI/Style/UIStyle.cs @@ -537,7 +537,7 @@ namespace Sunny.UI return values; } - public static List GetTranslateControls(this Control ctrl, string interfaceName) + public static List GetInterfaceControls(this Control ctrl, string interfaceName) { List values = new List(); @@ -550,7 +550,7 @@ namespace Sunny.UI if (obj.Controls.Count > 0) { - values.AddRange(obj.GetTranslateControls(interfaceName)); + values.AddRange(obj.GetInterfaceControls(interfaceName)); } }