* UITextBox:增加FocusedSelectAll属性,激活时全选。

This commit is contained in:
Sunny 2020-09-03 22:13:14 +08:00
parent 866cbcd2c5
commit 979b7b5c09
5 changed files with 27 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -478,10 +478,21 @@ namespace Sunny.UI
protected override void OnGotFocus(EventArgs e) protected override void OnGotFocus(EventArgs e)
{ {
base.OnGotFocus(e); base.OnGotFocus(e);
SelectionStart = Text.Length;
SelectionLength = 0; if (FocusedSelectAll)
{
SelectAll();
}
else
{
SelectionStart = Text.Length;
SelectionLength = 0;
}
} }
[DefaultValue(false)]
public bool FocusedSelectAll { get; set; }
protected override void OnLeave(EventArgs e) protected override void OnLeave(EventArgs e)
{ {
base.OnLeave(e); base.OnLeave(e);

View File

@ -83,6 +83,14 @@ namespace Sunny.UI
Leave?.Invoke(sender, e); Leave?.Invoke(sender, e);
} }
[DefaultValue(false)]
[Description("激活时选中全部文字"), Category("SunnyUI")]
public bool FocusedSelectAll
{
get => edit.FocusedSelectAll;
set => edit.FocusedSelectAll = value;
}
private void UITextBox_TextAlignmentChange(object sender, ContentAlignment alignment) private void UITextBox_TextAlignmentChange(object sender, ContentAlignment alignment)
{ {
if (edit == null) return; if (edit == null) return;
@ -129,6 +137,10 @@ namespace Sunny.UI
private void Edit_MouseEnter(object sender, EventArgs e) private void Edit_MouseEnter(object sender, EventArgs e)
{ {
Cursor = editCursor; Cursor = editCursor;
if (FocusedSelectAll)
{
SelectAll();
}
} }
private void OnMouseWheel(object sender, MouseEventArgs e) private void OnMouseWheel(object sender, MouseEventArgs e)
@ -191,6 +203,7 @@ namespace Sunny.UI
public void Select(int start, int length) public void Select(int start, int length)
{ {
edit.Focus();
edit.Select(start, length); edit.Select(start, length);
} }
@ -231,6 +244,7 @@ namespace Sunny.UI
public void SelectAll() public void SelectAll()
{ {
edit.Focus();
edit.SelectAll(); edit.SelectAll();
} }