* UIComboBox: 增加了SelectionChangeCommitted事件,下拉框显示鼠标点击条目时响应

This commit is contained in:
Sunny 2024-10-28 22:46:47 +08:00
parent 2d98153089
commit 88bce81140
3 changed files with 102 additions and 27 deletions

View File

@ -28,38 +28,38 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.listBox = new Sunny.UI.UIListBox(); listBox = new UIListBox();
this.SuspendLayout(); SuspendLayout();
// //
// listBox // listBox
// //
this.listBox.BackColor = System.Drawing.Color.Transparent; listBox.BackColor = System.Drawing.Color.Transparent;
this.listBox.Dock = System.Windows.Forms.DockStyle.Fill; listBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox.FillColor = System.Drawing.Color.White; listBox.FillColor = System.Drawing.Color.White;
this.listBox.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); listBox.Font = new System.Drawing.Font("宋体", 12F);
this.listBox.FormatString = ""; listBox.HoverColor = System.Drawing.Color.FromArgb(155, 200, 255);
this.listBox.ItemSelectForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255))))); listBox.ItemSelectForeColor = System.Drawing.Color.FromArgb(235, 243, 255);
this.listBox.Location = new System.Drawing.Point(0, 0); listBox.Location = new System.Drawing.Point(0, 0);
this.listBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); listBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.listBox.MinimumSize = new System.Drawing.Size(1, 1); listBox.MinimumSize = new System.Drawing.Size(1, 1);
this.listBox.Name = "listBox"; listBox.Name = "listBox";
this.listBox.Padding = new System.Windows.Forms.Padding(2); listBox.Padding = new System.Windows.Forms.Padding(2);
this.listBox.Radius = 0; listBox.Radius = 0;
this.listBox.Size = new System.Drawing.Size(184, 210); listBox.ShowText = false;
this.listBox.TabIndex = 3; listBox.Size = new System.Drawing.Size(184, 210);
this.listBox.Text = null; listBox.TabIndex = 3;
this.listBox.Click += new System.EventHandler(this.ListBox_Click); listBox.Text = null;
this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged); listBox.KeyDown += listBox_KeyDown;
this.listBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listBox_KeyDown); listBox.Click += ListBox_Click;
listBox.SelectedIndexChanged += listBox_SelectedIndexChanged;
// //
// UIComboBoxItem // UIComboBoxItem
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Controls.Add(this.listBox); Controls.Add(listBox);
this.Name = "UIComboBoxItem"; Name = "UIComboBoxItem";
this.Size = new System.Drawing.Size(184, 210); Size = new System.Drawing.Size(184, 210);
this.ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion

View File

@ -1,4 +1,64 @@
<root> <?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -40,6 +40,7 @@
* 2023-08-11: V3.4.1 Items.Clear后DropDownStyle为DropDown时Text * 2023-08-11: V3.4.1 Items.Clear后DropDownStyle为DropDown时Text
* 2023-12-26: V3.6.2 * 2023-12-26: V3.6.2
* 2024-01-27: V3.6.3 SelectedIndex报错 * 2024-01-27: V3.6.3 SelectedIndex报错
* 2024-10-28: V3.7.2 SelectionChangeCommitted事件
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -71,6 +72,7 @@ namespace Sunny.UI
ListBox.SelectedValueChanged += ListBox_SelectedValueChanged; ListBox.SelectedValueChanged += ListBox_SelectedValueChanged;
ListBox.ItemsClear += ListBox_ItemsClear; ListBox.ItemsClear += ListBox_ItemsClear;
ListBox.ItemsRemove += ListBox_ItemsRemove; ListBox.ItemsRemove += ListBox_ItemsRemove;
ListBox.MouseClick += ListBox_MouseClick;
filterForm.BeforeListClick += ListBox_Click; filterForm.BeforeListClick += ListBox_Click;
@ -82,6 +84,19 @@ namespace Sunny.UI
CreateInstance(); 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)] [Browsable(false)]
public override string[] FormTranslatorProperties { get; } public override string[] FormTranslatorProperties { get; }