* UITextBox: 增加SelectionChanged事件

This commit is contained in:
Sunny 2022-07-17 20:15:20 +08:00
parent 3afec3c581
commit e3f550e6e9
5 changed files with 35 additions and 2 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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);
}

View File

@ -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);

View File

@ -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);