diff --git a/SunnyUI/Controls/DropItem/UIToolStripDropDown.cs b/SunnyUI/Controls/DropItem/UIToolStripDropDown.cs index 95029e46..9aae6db8 100644 --- a/SunnyUI/Controls/DropItem/UIToolStripDropDown.cs +++ b/SunnyUI/Controls/DropItem/UIToolStripDropDown.cs @@ -31,7 +31,7 @@ namespace Sunny.UI { private UIDropDown itemForm; - public UIToolStripDropDown(UIDropDownItem item) + public UIToolStripDropDown(UIDropDownItem item, bool autoClose = true) { itemForm = new UIDropDown(item); itemForm.ValueChanged += ItemForm_ValueChanged; @@ -39,6 +39,7 @@ namespace Sunny.UI itemForm.Closed += ItemForm_Closed; itemForm.Opened += ItemForm_Opened; itemForm.Opening += ItemForm_Opening; + itemForm.AutoClose = autoClose; } public Size ItemSize => itemForm.Size; diff --git a/SunnyUI/Controls/UIEdit.cs b/SunnyUI/Controls/UIEdit.cs index 7321820a..a4da0140 100644 --- a/SunnyUI/Controls/UIEdit.cs +++ b/SunnyUI/Controls/UIEdit.cs @@ -206,6 +206,20 @@ namespace Sunny.UI } } + public event OnSelectionChanged SelectionChanged; + + protected override void OnKeyUp(KeyEventArgs e) + { + base.OnKeyUp(e); + SelectionChanged?.Invoke(this, new UITextBoxSelectionArgs() { SelectionStart = this.SelectionStart, Text = this.Text }); + } + + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + SelectionChanged?.Invoke(this, new UITextBoxSelectionArgs() { SelectionStart = this.SelectionStart, Text = this.Text }); + } + protected override void OnKeyDown(KeyEventArgs e) { if (!Multiline) diff --git a/SunnyUI/Controls/UIGlobal.cs b/SunnyUI/Controls/UIGlobal.cs index 11a9ae33..21b755b5 100644 --- a/SunnyUI/Controls/UIGlobal.cs +++ b/SunnyUI/Controls/UIGlobal.cs @@ -52,5 +52,14 @@ namespace Sunny.UI } } + public class UITextBoxSelectionArgs : EventArgs + { + public int SelectionStart { get; set; } + + public string Text { get; set; } + } + + public delegate void OnSelectionChanged(object sender, UITextBoxSelectionArgs e); + public delegate void OnDateTimeChanged(object sender, UIDateTimeArgs e); } \ No newline at end of file diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index f7298a71..00e781db 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -35,6 +35,7 @@ * 2022-04-11: V3.1.3 增加对按钮设置ToolTip * 2022-06-10: V3.1.9 尺寸改变时重绘 * 2022-06-23: V3.2.0 重写水印文字,解决不同背景色下泛白的问题 + * 2022-07-17: V3.2.1 增加SelectionChanged事件 ******************************************************************************/ using System; @@ -91,6 +92,7 @@ namespace Sunny.UI edit.MouseDown += Edit_MouseDown; edit.MouseUp += Edit_MouseUp; edit.MouseMove += Edit_MouseMove; + edit.SelectionChanged += Edit_SelectionChanged; btn.Parent = this; btn.Visible = false; @@ -122,6 +124,13 @@ namespace Sunny.UI TextAlignmentChange += UITextBox_TextAlignmentChange; } + private void Edit_SelectionChanged(object sender, UITextBoxSelectionArgs e) + { + SelectionChanged?.Invoke(this, e); + } + + public event OnSelectionChanged SelectionChanged; + public void SetButtonToolTip(ToolTip toolTip, string tipText) { toolTip.SetToolTip(btn, tipText); diff --git a/SunnyUI/Controls/UITreeView.cs b/SunnyUI/Controls/UITreeView.cs index af2db2f6..31f0f338 100644 --- a/SunnyUI/Controls/UITreeView.cs +++ b/SunnyUI/Controls/UITreeView.cs @@ -87,7 +87,7 @@ namespace Sunny.UI view.AfterLabelEdit += View_AfterLabelEdit; } - internal int DrawLeft(TreeNode node) + public int DrawLeft(TreeNode node) { if (view == null || node == null) return 0; return view.DrawLeft(node);