From 88bce811405d76c544078dfdc45358f79794c82b Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 28 Oct 2024 22:46:47 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIComboBox:=20=E5=A2=9E=E5=8A=A0=E4=BA=86Se?= =?UTF-8?q?lectionChangeCommitted=E4=BA=8B=E4=BB=B6=EF=BC=8C=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E6=A1=86=E6=98=BE=E7=A4=BA=E9=BC=A0=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=9D=A1=E7=9B=AE=E6=97=B6=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropItem/UIComboBoxItem.Designer.cs | 52 ++++++++-------- SunnyUI/Controls/DropItem/UIComboBoxItem.resx | 62 ++++++++++++++++++- SunnyUI/Controls/UIComboBox.cs | 15 +++++ 3 files changed, 102 insertions(+), 27 deletions(-) diff --git a/SunnyUI/Controls/DropItem/UIComboBoxItem.Designer.cs b/SunnyUI/Controls/DropItem/UIComboBoxItem.Designer.cs index 5fda19b7..59e24a3b 100644 --- a/SunnyUI/Controls/DropItem/UIComboBoxItem.Designer.cs +++ b/SunnyUI/Controls/DropItem/UIComboBoxItem.Designer.cs @@ -28,38 +28,38 @@ /// private void InitializeComponent() { - this.listBox = new Sunny.UI.UIListBox(); - this.SuspendLayout(); + listBox = new UIListBox(); + SuspendLayout(); // // listBox // - this.listBox.BackColor = System.Drawing.Color.Transparent; - this.listBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.listBox.FillColor = System.Drawing.Color.White; - this.listBox.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.listBox.FormatString = ""; - this.listBox.ItemSelectForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255))))); - this.listBox.Location = new System.Drawing.Point(0, 0); - this.listBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.listBox.MinimumSize = new System.Drawing.Size(1, 1); - this.listBox.Name = "listBox"; - this.listBox.Padding = new System.Windows.Forms.Padding(2); - this.listBox.Radius = 0; - this.listBox.Size = new System.Drawing.Size(184, 210); - this.listBox.TabIndex = 3; - this.listBox.Text = null; - this.listBox.Click += new System.EventHandler(this.ListBox_Click); - this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged); - this.listBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listBox_KeyDown); + listBox.BackColor = System.Drawing.Color.Transparent; + listBox.Dock = System.Windows.Forms.DockStyle.Fill; + listBox.FillColor = System.Drawing.Color.White; + listBox.Font = new System.Drawing.Font("宋体", 12F); + listBox.HoverColor = System.Drawing.Color.FromArgb(155, 200, 255); + listBox.ItemSelectForeColor = System.Drawing.Color.FromArgb(235, 243, 255); + listBox.Location = new System.Drawing.Point(0, 0); + listBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + listBox.MinimumSize = new System.Drawing.Size(1, 1); + listBox.Name = "listBox"; + listBox.Padding = new System.Windows.Forms.Padding(2); + listBox.Radius = 0; + listBox.ShowText = false; + listBox.Size = new System.Drawing.Size(184, 210); + listBox.TabIndex = 3; + listBox.Text = null; + listBox.KeyDown += listBox_KeyDown; + listBox.Click += ListBox_Click; + listBox.SelectedIndexChanged += listBox_SelectedIndexChanged; // // UIComboBoxItem // - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.Controls.Add(this.listBox); - this.Name = "UIComboBoxItem"; - this.Size = new System.Drawing.Size(184, 210); - this.ResumeLayout(false); - + AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + Controls.Add(listBox); + Name = "UIComboBoxItem"; + Size = new System.Drawing.Size(184, 210); + ResumeLayout(false); } #endregion diff --git a/SunnyUI/Controls/DropItem/UIComboBoxItem.resx b/SunnyUI/Controls/DropItem/UIComboBoxItem.resx index f298a7be..8b2ff64a 100644 --- a/SunnyUI/Controls/DropItem/UIComboBoxItem.resx +++ b/SunnyUI/Controls/DropItem/UIComboBoxItem.resx @@ -1,4 +1,64 @@ - + + + diff --git a/SunnyUI/Controls/UIComboBox.cs b/SunnyUI/Controls/UIComboBox.cs index 1f997564..a78265c6 100644 --- a/SunnyUI/Controls/UIComboBox.cs +++ b/SunnyUI/Controls/UIComboBox.cs @@ -40,6 +40,7 @@ * 2023-08-11: V3.4.1 Items.Clear后,DropDownStyle为DropDown时,不清空Text * 2023-12-26: V3.6.2 增加下拉界面的滚动条设置 * 2024-01-27: V3.6.3 修复在窗体构造函数设置SelectedIndex报错 + * 2024-10-28: V3.7.2 增加了SelectionChangeCommitted事件,下拉框显示鼠标点击条目时响应 ******************************************************************************/ using System; @@ -71,6 +72,7 @@ namespace Sunny.UI ListBox.SelectedValueChanged += ListBox_SelectedValueChanged; ListBox.ItemsClear += ListBox_ItemsClear; ListBox.ItemsRemove += ListBox_ItemsRemove; + ListBox.MouseClick += ListBox_MouseClick; filterForm.BeforeListClick += ListBox_Click; @@ -82,6 +84,19 @@ namespace Sunny.UI CreateInstance(); } + private void ListBox_MouseClick(object sender, MouseEventArgs e) + { + //SelectionChangeCommitted + UIListBox listBox = (UIListBox)sender; + int index = listBox.IndexFromPoint(e.X, e.Y); + if (index != -1) + { + SelectionChangeCommitted?.Invoke(this, EventArgs.Empty); + } + } + + public event EventHandler SelectionChangeCommitted; + [Browsable(false)] public override string[] FormTranslatorProperties { get; }