2020-05-11 21:11:29 +08:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
2021-02-20 15:45:47 +08:00
|
|
|
|
* CopyRight (C) 2012-2021 ShenYongHua(沈永华).
|
|
|
|
|
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
2020-05-11 21:11:29 +08:00
|
|
|
|
*
|
|
|
|
|
* Blog: https://www.cnblogs.com/yhuse
|
|
|
|
|
* Gitee: https://gitee.com/yhuse/SunnyUI
|
|
|
|
|
* GitHub: https://github.com/yhuse/SunnyUI
|
|
|
|
|
*
|
|
|
|
|
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
|
|
|
|
* If you use this code, please keep this note.
|
|
|
|
|
* 如果您使用此代码,请保留此说明。
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* 文件名称: UITextBox.cs
|
|
|
|
|
* 文件说明: 输入框
|
2021-01-05 16:43:02 +08:00
|
|
|
|
* 当前版本: V3.0
|
2020-05-11 21:11:29 +08:00
|
|
|
|
* 创建日期: 2020-01-01
|
|
|
|
|
*
|
|
|
|
|
* 2020-01-01: V2.2.0 增加文件说明
|
2020-06-03 14:10:28 +08:00
|
|
|
|
* 2020-06-03: V2.2.5 增加多行,增加滚动条
|
2021-08-17 16:55:01 +08:00
|
|
|
|
* 2020-09-03: V2.2.7 增加FocusedSelectAll属性,激活时全选
|
|
|
|
|
* 2021-04-15: V3.0.3 修改文字可以居中显示
|
|
|
|
|
* 2021-04-17: V3.0.3 不限制高度为根据字体计算,可进行调整,解决多行输入时不能输入回车的问题
|
2021-04-18 22:27:40 +08:00
|
|
|
|
* 2021-04-18: V3.0.3 增加ShowScrollBar属性,单独控制垂直滚动条
|
2021-08-17 16:55:01 +08:00
|
|
|
|
* 2021-06-01: V3.0.4 增加图标和字体图标的显示
|
|
|
|
|
* 2021-07-18: V3.0.5 修改Focus可用
|
|
|
|
|
* 2021-08-03: V3.0.5 增加GotFocus和LostFocus事件
|
|
|
|
|
* 2021-08-15: V3.0.6 重写了水印文字的画法,并增加水印文字颜色
|
2020-05-11 21:11:29 +08:00
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-06-05 21:48:58 +08:00
|
|
|
|
using System.Collections;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2020-06-05 21:48:58 +08:00
|
|
|
|
using System.Drawing.Design;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Sunny.UI
|
|
|
|
|
{
|
|
|
|
|
[DefaultEvent("TextChanged")]
|
|
|
|
|
[DefaultProperty("Text")]
|
2021-08-16 21:51:03 +08:00
|
|
|
|
public sealed partial class UITextBox : UIPanel, ISymbol, IToolTip
|
2020-05-11 21:11:29 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly UIEdit edit = new UIEdit();
|
2020-06-03 14:10:28 +08:00
|
|
|
|
private readonly UIScrollBar bar = new UIScrollBar();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
|
|
|
|
public UITextBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-04-16 15:45:58 +08:00
|
|
|
|
SetStyleFlags();
|
2020-06-06 23:08:16 +08:00
|
|
|
|
CalcEditHeight();
|
2021-04-18 22:27:40 +08:00
|
|
|
|
Height = MinHeight;
|
2020-06-05 21:48:58 +08:00
|
|
|
|
ShowText = false;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
Font = UIFontColor.Font;
|
2021-06-01 17:49:55 +08:00
|
|
|
|
Padding = new Padding(0);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
2020-06-06 23:08:16 +08:00
|
|
|
|
edit.Top = (Height - edit.Height) / 2;
|
2021-05-12 14:44:39 +08:00
|
|
|
|
edit.Left = 4;
|
|
|
|
|
edit.Width = Width - 8;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edit.Text = String.Empty;
|
|
|
|
|
edit.BorderStyle = BorderStyle.None;
|
2021-08-23 13:27:57 +08:00
|
|
|
|
edit.TextChanged += Edit_TextChanged;
|
|
|
|
|
edit.KeyDown += Edit_OnKeyDown;
|
|
|
|
|
edit.KeyUp += Edit_OnKeyUp;
|
|
|
|
|
edit.KeyPress += Edit_OnKeyPress;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
edit.MouseEnter += Edit_MouseEnter;
|
2020-07-20 21:29:33 +08:00
|
|
|
|
edit.Click += Edit_Click;
|
|
|
|
|
edit.DoubleClick += Edit_DoubleClick;
|
2020-07-27 23:17:52 +08:00
|
|
|
|
edit.Leave += Edit_Leave;
|
2021-07-05 22:09:10 +08:00
|
|
|
|
edit.Validated += Edit_Validated;
|
|
|
|
|
edit.Validating += Edit_Validating;
|
2021-08-01 20:33:05 +08:00
|
|
|
|
edit.GotFocus += Edit_GotFocus;
|
|
|
|
|
edit.LostFocus += Edit_LostFocus;
|
2021-08-23 13:27:57 +08:00
|
|
|
|
edit.MouseLeave += Edit_MouseLeave;
|
|
|
|
|
edit.MouseWheel += Edit_MouseWheel;
|
|
|
|
|
edit.MouseDown += Edit_MouseDown;
|
|
|
|
|
edit.MouseUp += Edit_MouseUp;
|
|
|
|
|
edit.MouseMove += Edit_MouseMove;
|
2020-05-27 21:13:48 +08:00
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edit.Invalidate();
|
|
|
|
|
Controls.Add(edit);
|
|
|
|
|
fillColor = Color.White;
|
|
|
|
|
Width = 150;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
|
|
|
|
|
bar.Parent = this;
|
|
|
|
|
bar.Dock = DockStyle.None;
|
|
|
|
|
bar.Style = UIStyle.Custom;
|
|
|
|
|
bar.Visible = false;
|
|
|
|
|
bar.ValueChanged += Bar_ValueChanged;
|
|
|
|
|
bar.MouseEnter += Bar_MouseEnter;
|
2021-04-18 22:27:40 +08:00
|
|
|
|
TextAlignment = ContentAlignment.MiddleLeft;
|
2020-06-06 23:08:16 +08:00
|
|
|
|
|
|
|
|
|
SizeChange();
|
2020-07-20 21:29:33 +08:00
|
|
|
|
|
|
|
|
|
editCursor = Cursor;
|
2020-07-27 23:17:52 +08:00
|
|
|
|
TextAlignmentChange += UITextBox_TextAlignmentChange;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 13:27:57 +08:00
|
|
|
|
private void Edit_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseMove?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseUp?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseDown?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new event MouseEventHandler MouseDown;
|
|
|
|
|
public new event MouseEventHandler MouseUp;
|
|
|
|
|
public new event MouseEventHandler MouseMove;
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseLeave?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:51:03 +08:00
|
|
|
|
public Control ExToolTipControl()
|
|
|
|
|
{
|
|
|
|
|
return edit;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 20:33:05 +08:00
|
|
|
|
private void Edit_LostFocus(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LostFocus?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_GotFocus(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GotFocus?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 22:09:10 +08:00
|
|
|
|
private void Edit_Validating(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Validating?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 20:33:05 +08:00
|
|
|
|
public new EventHandler GotFocus;
|
|
|
|
|
public new EventHandler LostFocus;
|
2021-07-05 22:09:10 +08:00
|
|
|
|
public new CancelEventHandler Validating;
|
|
|
|
|
public new event EventHandler Validated;
|
2021-08-23 13:27:57 +08:00
|
|
|
|
public new EventHandler MouseLeave;
|
2021-07-05 22:09:10 +08:00
|
|
|
|
|
|
|
|
|
private void Edit_Validated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Validated?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-18 15:24:32 +08:00
|
|
|
|
public new void Focus()
|
|
|
|
|
{
|
|
|
|
|
base.Focus();
|
|
|
|
|
edit.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-08 16:24:12 +08:00
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public TextBox TextBox => edit;
|
|
|
|
|
|
2020-07-27 23:17:52 +08:00
|
|
|
|
private void Edit_Leave(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-07-05 22:09:10 +08:00
|
|
|
|
Leave?.Invoke(this, e);
|
2020-07-27 23:17:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 23:34:38 +08:00
|
|
|
|
protected override void OnEnabledChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnEnabledChanged(e);
|
|
|
|
|
edit.BackColor = Enabled ? Color.White : FillDisableColor;
|
|
|
|
|
edit.Enabled = Enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 15:46:44 +08:00
|
|
|
|
public override bool Focused => edit.Focused;
|
2020-09-21 22:12:36 +08:00
|
|
|
|
|
2020-09-03 22:13:14 +08:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
[Description("激活时选中全部文字"), Category("SunnyUI")]
|
|
|
|
|
public bool FocusedSelectAll
|
|
|
|
|
{
|
|
|
|
|
get => edit.FocusedSelectAll;
|
|
|
|
|
set => edit.FocusedSelectAll = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 23:17:52 +08:00
|
|
|
|
private void UITextBox_TextAlignmentChange(object sender, ContentAlignment alignment)
|
|
|
|
|
{
|
2020-08-08 21:55:50 +08:00
|
|
|
|
if (edit == null) return;
|
2020-07-27 23:17:52 +08:00
|
|
|
|
if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.MiddleLeft ||
|
|
|
|
|
alignment == ContentAlignment.BottomLeft)
|
|
|
|
|
edit.TextAlign = HorizontalAlignment.Left;
|
|
|
|
|
|
|
|
|
|
if (alignment == ContentAlignment.TopCenter || alignment == ContentAlignment.MiddleCenter ||
|
|
|
|
|
alignment == ContentAlignment.BottomCenter)
|
|
|
|
|
edit.TextAlign = HorizontalAlignment.Center;
|
|
|
|
|
|
|
|
|
|
if (alignment == ContentAlignment.TopRight || alignment == ContentAlignment.MiddleRight ||
|
|
|
|
|
alignment == ContentAlignment.BottomRight)
|
|
|
|
|
edit.TextAlign = HorizontalAlignment.Right;
|
2020-07-20 21:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-08-08 21:55:50 +08:00
|
|
|
|
DoubleClick?.Invoke(this, e);
|
2020-07-20 21:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new event EventHandler DoubleClick;
|
|
|
|
|
public new event EventHandler Click;
|
|
|
|
|
|
|
|
|
|
private void Edit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-08-08 21:55:50 +08:00
|
|
|
|
Click?.Invoke(this, e);
|
2020-07-20 21:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnCursorChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnCursorChanged(e);
|
|
|
|
|
edit.Cursor = Cursor;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 21:29:33 +08:00
|
|
|
|
private Cursor editCursor;
|
|
|
|
|
|
2020-06-03 14:10:28 +08:00
|
|
|
|
private void Bar_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-07-20 21:29:33 +08:00
|
|
|
|
editCursor = Cursor;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-07-20 21:29:33 +08:00
|
|
|
|
Cursor = editCursor;
|
2020-09-03 22:13:14 +08:00
|
|
|
|
if (FocusedSelectAll)
|
|
|
|
|
{
|
|
|
|
|
SelectAll();
|
|
|
|
|
}
|
2020-06-03 14:10:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 13:27:57 +08:00
|
|
|
|
private void Edit_MouseWheel(object sender, MouseEventArgs e)
|
2020-06-03 14:10:28 +08:00
|
|
|
|
{
|
|
|
|
|
base.OnMouseWheel(e);
|
2020-06-14 19:35:38 +08:00
|
|
|
|
if (bar != null && bar.Visible && edit != null)
|
2020-06-03 14:10:28 +08:00
|
|
|
|
{
|
2020-06-06 23:08:16 +08:00
|
|
|
|
var si = ScrollBarInfo.GetInfo(edit.Handle);
|
2020-06-03 14:10:28 +08:00
|
|
|
|
if (e.Delta > 10)
|
|
|
|
|
{
|
|
|
|
|
if (si.nPos > 0)
|
|
|
|
|
{
|
2020-06-06 23:08:16 +08:00
|
|
|
|
ScrollBarInfo.ScrollUp(edit.Handle);
|
2020-06-03 14:10:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (e.Delta < -10)
|
|
|
|
|
{
|
|
|
|
|
if (si.nPos < si.ScrollMax)
|
|
|
|
|
{
|
2020-06-06 23:08:16 +08:00
|
|
|
|
ScrollBarInfo.ScrollDown(edit.Handle);
|
2020-06-03 14:10:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetScrollInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Bar_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (edit != null)
|
|
|
|
|
{
|
|
|
|
|
ScrollBarInfo.SetScrollValue(edit.Handle, bar.Value);
|
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 12:16:27 +08:00
|
|
|
|
private bool multiline;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool Multiline
|
|
|
|
|
{
|
|
|
|
|
get => multiline;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
multiline = value;
|
|
|
|
|
edit.Multiline = value;
|
2021-04-18 22:27:40 +08:00
|
|
|
|
// edit.ScrollBars = value ? ScrollBars.Vertical : ScrollBars.None;
|
|
|
|
|
// bar.Visible = multiline;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
|
2021-04-18 22:27:40 +08:00
|
|
|
|
if (value && Type != UIEditType.String)
|
|
|
|
|
{
|
|
|
|
|
Type = UIEditType.String;
|
|
|
|
|
}
|
2020-06-03 14:10:28 +08:00
|
|
|
|
|
2020-06-03 12:16:27 +08:00
|
|
|
|
SizeChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 22:27:40 +08:00
|
|
|
|
private bool showScrollBar;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
[Description("显示垂直滚动条"), Category("SunnyUI")]
|
|
|
|
|
public bool ShowScrollBar
|
|
|
|
|
{
|
|
|
|
|
get => showScrollBar;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
value = value && Multiline;
|
|
|
|
|
showScrollBar = value;
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
edit.ScrollBars = ScrollBars.Vertical;
|
|
|
|
|
bar.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
edit.ScrollBars = ScrollBars.None;
|
|
|
|
|
bar.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 14:10:28 +08:00
|
|
|
|
[DefaultValue(true)]
|
|
|
|
|
public bool WordWarp
|
|
|
|
|
{
|
|
|
|
|
get => edit.WordWrap;
|
|
|
|
|
set => edit.WordWrap = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Select(int start, int length)
|
|
|
|
|
{
|
2020-09-03 22:13:14 +08:00
|
|
|
|
edit.Focus();
|
2020-06-03 14:10:28 +08:00
|
|
|
|
edit.Select(start, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ScrollToCaret()
|
|
|
|
|
{
|
|
|
|
|
edit.ScrollToCaret();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 13:27:57 +08:00
|
|
|
|
private void Edit_OnKeyPress(object sender, KeyPressEventArgs e)
|
2020-05-27 21:13:48 +08:00
|
|
|
|
{
|
2021-07-05 22:09:10 +08:00
|
|
|
|
KeyPress?.Invoke(this, e);
|
2020-05-27 21:13:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 13:27:57 +08:00
|
|
|
|
private void Edit_OnKeyDown(object sender, KeyEventArgs e)
|
2020-06-05 21:48:58 +08:00
|
|
|
|
{
|
2020-06-20 21:00:15 +08:00
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
{
|
2021-07-05 22:09:10 +08:00
|
|
|
|
DoEnter?.Invoke(this, e);
|
2020-06-20 21:00:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 22:09:10 +08:00
|
|
|
|
KeyDown?.Invoke(this, e);
|
2020-06-05 21:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-20 21:00:15 +08:00
|
|
|
|
public event EventHandler DoEnter;
|
|
|
|
|
|
2021-08-23 13:27:57 +08:00
|
|
|
|
private void Edit_OnKeyUp(object sender, KeyEventArgs e)
|
2020-05-27 21:13:48 +08:00
|
|
|
|
{
|
2021-07-05 22:09:10 +08:00
|
|
|
|
KeyUp?.Invoke(this, e);
|
2020-05-27 21:13:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 23:43:20 +08:00
|
|
|
|
[DefaultValue(null)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("水印文字"), Category("SunnyUI")]
|
2020-05-25 23:43:20 +08:00
|
|
|
|
public string Watermark
|
|
|
|
|
{
|
|
|
|
|
get => edit.Watermark;
|
|
|
|
|
set => edit.Watermark = value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 15:46:44 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "Gray")]
|
|
|
|
|
[Description("水印文字颜色"), Category("SunnyUI")]
|
|
|
|
|
public Color WatermarkColor
|
|
|
|
|
{
|
|
|
|
|
get => edit.WaterMarkColor;
|
|
|
|
|
set => edit.WaterMarkColor = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public void SelectAll()
|
|
|
|
|
{
|
2020-09-03 22:13:14 +08:00
|
|
|
|
edit.Focus();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edit.SelectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CheckMaxMin()
|
|
|
|
|
{
|
|
|
|
|
edit.CheckMaxMin();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 10:22:35 +08:00
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public new event EventHandler TextChanged;
|
|
|
|
|
|
2020-05-27 21:13:48 +08:00
|
|
|
|
public new event KeyEventHandler KeyDown;
|
|
|
|
|
|
|
|
|
|
public new event KeyEventHandler KeyUp;
|
|
|
|
|
|
|
|
|
|
public new event KeyPressEventHandler KeyPress;
|
|
|
|
|
|
2020-08-08 21:55:50 +08:00
|
|
|
|
public new event EventHandler Leave;
|
2020-07-27 23:17:52 +08:00
|
|
|
|
|
2021-08-23 13:27:57 +08:00
|
|
|
|
private void Edit_TextChanged(object s, EventArgs e)
|
2020-05-11 21:11:29 +08:00
|
|
|
|
{
|
2020-05-15 10:22:35 +08:00
|
|
|
|
TextChanged?.Invoke(this, e);
|
2020-06-03 14:10:28 +08:00
|
|
|
|
SetScrollInfo();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnFontChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnFontChanged(e);
|
|
|
|
|
edit.Font = Font;
|
2020-06-06 23:08:16 +08:00
|
|
|
|
CalcEditHeight();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
SizeChange();
|
2020-06-06 23:08:16 +08:00
|
|
|
|
Invalidate();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSizeChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SizeChange();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 12:22:11 +08:00
|
|
|
|
protected override void OnPaddingChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnPaddingChanged(e);
|
2021-05-12 14:44:39 +08:00
|
|
|
|
SizeChange();
|
2021-05-12 12:22:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 14:10:28 +08:00
|
|
|
|
public void SetScrollInfo()
|
|
|
|
|
{
|
|
|
|
|
if (bar == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var si = ScrollBarInfo.GetInfo(edit.Handle);
|
|
|
|
|
if (si.ScrollMax > 0)
|
|
|
|
|
{
|
|
|
|
|
bar.Maximum = si.ScrollMax;
|
|
|
|
|
bar.Value = si.nPos;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bar.Maximum = si.ScrollMax;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 22:27:40 +08:00
|
|
|
|
private int MinHeight;
|
|
|
|
|
private int MaxHeight;
|
2020-06-03 12:16:27 +08:00
|
|
|
|
|
2020-06-06 23:08:16 +08:00
|
|
|
|
private void CalcEditHeight()
|
2020-05-11 21:11:29 +08:00
|
|
|
|
{
|
2021-07-15 13:54:31 +08:00
|
|
|
|
TextBox edt = new();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edt.Font = edit.Font;
|
2021-04-18 22:27:40 +08:00
|
|
|
|
MinHeight = edt.PreferredHeight;
|
|
|
|
|
edt.BorderStyle = BorderStyle.None;
|
|
|
|
|
MaxHeight = edt.PreferredHeight * 2 + MinHeight - edt.PreferredHeight;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edt.Dispose();
|
2020-06-06 23:08:16 +08:00
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
2020-06-06 23:08:16 +08:00
|
|
|
|
private void SizeChange()
|
|
|
|
|
{
|
2020-06-03 12:16:27 +08:00
|
|
|
|
if (!multiline)
|
|
|
|
|
{
|
2021-04-18 22:27:40 +08:00
|
|
|
|
if (Height < MinHeight) Height = MinHeight;
|
|
|
|
|
if (Height > MaxHeight) Height = MaxHeight;
|
2020-06-06 23:08:16 +08:00
|
|
|
|
|
2020-06-03 12:16:27 +08:00
|
|
|
|
edit.Top = (Height - edit.Height) / 2;
|
2021-06-01 17:49:55 +08:00
|
|
|
|
if (icon == null && Symbol == 0)
|
2021-05-12 14:44:39 +08:00
|
|
|
|
{
|
|
|
|
|
edit.Left = 4 + Padding.Left;
|
|
|
|
|
edit.Width = Width - 8 - Padding.Left - Padding.Right;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-01 17:49:55 +08:00
|
|
|
|
if (icon != null)
|
|
|
|
|
{
|
|
|
|
|
edit.Left = 4 + iconSize + Padding.Left;
|
|
|
|
|
edit.Width = Width - 8 - iconSize - Padding.Left - Padding.Right;
|
|
|
|
|
}
|
|
|
|
|
else if (Symbol > 0)
|
|
|
|
|
{
|
|
|
|
|
edit.Left = 4 + SymbolSize + Padding.Left;
|
|
|
|
|
edit.Width = Width - 8 - SymbolSize - Padding.Left - Padding.Right;
|
|
|
|
|
}
|
2021-05-12 14:44:39 +08:00
|
|
|
|
}
|
2020-06-03 12:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
edit.Top = 3;
|
|
|
|
|
edit.Height = Height - 6;
|
|
|
|
|
edit.Left = 1;
|
|
|
|
|
edit.Width = Width - 2;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
bar.Top = 2;
|
|
|
|
|
bar.Width = ScrollBarInfo.VerticalScrollBarWidth();
|
|
|
|
|
bar.Left = Width - bar.Width - 1;
|
|
|
|
|
bar.Height = Height - 4;
|
|
|
|
|
bar.BringToFront();
|
|
|
|
|
|
|
|
|
|
SetScrollInfo();
|
2020-06-03 12:16:27 +08:00
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnGotFocus(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnGotFocus(e);
|
|
|
|
|
edit.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
edit.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue('\0')]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("密码掩码"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public char PasswordChar
|
|
|
|
|
{
|
|
|
|
|
get => edit.PasswordChar;
|
|
|
|
|
set => edit.PasswordChar = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("是否只读"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public bool ReadOnly
|
|
|
|
|
{
|
|
|
|
|
get => edit.ReadOnly;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
edit.ReadOnly = value;
|
2021-01-15 23:34:38 +08:00
|
|
|
|
edit.BackColor = Enabled ? Color.White : FillDisableColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("输入类型"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue(UIEditType.String)]
|
|
|
|
|
public UIEditType Type
|
|
|
|
|
{
|
|
|
|
|
get => edit.Type;
|
|
|
|
|
set => edit.Type = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当InputType为数字类型时,能输入的最大值
|
|
|
|
|
/// </summary>
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("当InputType为数字类型时,能输入的最大值。"), Category("SunnyUI")]
|
2020-06-05 21:48:58 +08:00
|
|
|
|
[DefaultValue(int.MaxValue)]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public double Maximum
|
|
|
|
|
{
|
|
|
|
|
get => edit.MaxValue;
|
|
|
|
|
set => edit.MaxValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当InputType为数字类型时,能输入的最小值
|
|
|
|
|
/// </summary>
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("当InputType为数字类型时,能输入的最小值。"), Category("SunnyUI")]
|
2020-06-05 21:48:58 +08:00
|
|
|
|
[DefaultValue(int.MinValue)]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public double Minimum
|
|
|
|
|
{
|
|
|
|
|
get => edit.MinValue;
|
|
|
|
|
set => edit.MinValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("是否判断最大值显示"), Category("SunnyUI")]
|
2021-06-01 18:10:43 +08:00
|
|
|
|
public bool MaximumEnabled
|
|
|
|
|
{
|
|
|
|
|
get => HasMaximum;
|
|
|
|
|
set => HasMaximum = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
[Description("是否判断最小值显示"), Category("SunnyUI")]
|
|
|
|
|
public bool MinimumEnabled
|
|
|
|
|
{
|
|
|
|
|
get => HasMinimum;
|
|
|
|
|
set => HasMinimum = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false), Browsable(false)]
|
|
|
|
|
[Description("是否判断最大值显示"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public bool HasMaximum
|
|
|
|
|
{
|
|
|
|
|
get => edit.HasMaxValue;
|
|
|
|
|
set => edit.HasMaxValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 18:10:43 +08:00
|
|
|
|
[DefaultValue(false), Browsable(false)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("是否判断最小值显示"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public bool HasMinimum
|
|
|
|
|
{
|
|
|
|
|
get => edit.HasMinValue;
|
|
|
|
|
set => edit.HasMinValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(0.00)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("浮点返回值"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public double DoubleValue
|
|
|
|
|
{
|
|
|
|
|
get => edit.DoubleValue;
|
|
|
|
|
set => edit.DoubleValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(0)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("整形返回值"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public int IntValue
|
|
|
|
|
{
|
|
|
|
|
get => edit.IntValue;
|
|
|
|
|
set => edit.IntValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("文本返回值"), Category("SunnyUI")]
|
|
|
|
|
[Browsable(true)]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue("")]
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get => edit.Text;
|
|
|
|
|
set => edit.Text = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当InputType为数字类型时,小数位数。
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("当InputType为数字类型时,小数位数。")]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[DefaultValue(2), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public int DecLength
|
|
|
|
|
{
|
|
|
|
|
get => edit.DecLength;
|
|
|
|
|
set => edit.DecLength = Math.Max(value, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
2020-08-09 15:06:09 +08:00
|
|
|
|
[Description("整形或浮点输入时,是否可空显示"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public bool CanEmpty
|
|
|
|
|
{
|
|
|
|
|
get => edit.CanEmpty;
|
|
|
|
|
set => edit.CanEmpty = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Empty()
|
|
|
|
|
{
|
|
|
|
|
if (edit.CanEmpty)
|
|
|
|
|
edit.Text = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEmpty => edit.Text == "";
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseDown(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ActiveControl = edit;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 21:48:58 +08:00
|
|
|
|
[DefaultValue(32767)]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public int MaxLength
|
|
|
|
|
{
|
|
|
|
|
get => edit.MaxLength;
|
|
|
|
|
set => edit.MaxLength = Math.Max(value, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetStyleColor(UIBaseStyle uiColor)
|
|
|
|
|
{
|
|
|
|
|
base.SetStyleColor(uiColor);
|
2021-01-15 23:34:38 +08:00
|
|
|
|
edit.BackColor = fillColor = Enabled ? Color.White : FillDisableColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edit.ForeColor = foreColor = UIFontColor.Primary;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
|
|
|
|
|
if (bar != null)
|
|
|
|
|
{
|
|
|
|
|
bar.ForeColor = uiColor.PrimaryColor;
|
|
|
|
|
bar.HoverColor = uiColor.ButtonFillHoverColor;
|
|
|
|
|
bar.PressColor = uiColor.ButtonFillPressColor;
|
|
|
|
|
bar.FillColor = Color.White;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AfterSetForeColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.AfterSetForeColor(color);
|
|
|
|
|
edit.ForeColor = color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AfterSetFillColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.AfterSetFillColor(color);
|
2021-01-15 23:34:38 +08:00
|
|
|
|
edit.BackColor = Enabled ? color : FillDisableColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum UIEditType
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字符串
|
|
|
|
|
/// </summary>
|
|
|
|
|
String,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 整数
|
|
|
|
|
/// </summary>
|
|
|
|
|
Integer,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 浮点数
|
|
|
|
|
/// </summary>
|
|
|
|
|
Double
|
|
|
|
|
}
|
2020-06-05 21:48:58 +08:00
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool AcceptsReturn
|
|
|
|
|
{
|
|
|
|
|
get => edit.AcceptsReturn;
|
|
|
|
|
set => edit.AcceptsReturn = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(AutoCompleteMode.None), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
|
|
|
|
|
public AutoCompleteMode AutoCompleteMode
|
|
|
|
|
{
|
|
|
|
|
get => edit.AutoCompleteMode;
|
|
|
|
|
set => edit.AutoCompleteMode = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
DefaultValue(AutoCompleteSource.None),
|
|
|
|
|
TypeConverterAttribute(typeof(TextBoxAutoCompleteSourceConverter)),
|
|
|
|
|
Browsable(true),
|
|
|
|
|
EditorBrowsable(EditorBrowsableState.Always)
|
|
|
|
|
]
|
|
|
|
|
public AutoCompleteSource AutoCompleteSource
|
|
|
|
|
{
|
|
|
|
|
get => edit.AutoCompleteSource;
|
|
|
|
|
set => edit.AutoCompleteSource = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
|
|
|
|
|
Localizable(true),
|
|
|
|
|
Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
|
|
|
|
|
Browsable(true),
|
|
|
|
|
EditorBrowsable(EditorBrowsableState.Always)
|
|
|
|
|
]
|
|
|
|
|
public AutoCompleteStringCollection AutoCompleteCustomSource
|
|
|
|
|
{
|
|
|
|
|
get => edit.AutoCompleteCustomSource;
|
|
|
|
|
set => edit.AutoCompleteCustomSource = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(CharacterCasing.Normal)]
|
|
|
|
|
public CharacterCasing CharacterCasing
|
|
|
|
|
{
|
|
|
|
|
get => edit.CharacterCasing;
|
|
|
|
|
set => edit.CharacterCasing = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Paste(string text)
|
|
|
|
|
{
|
|
|
|
|
edit.Paste(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class TextBoxAutoCompleteSourceConverter : EnumConverter
|
|
|
|
|
{
|
|
|
|
|
public TextBoxAutoCompleteSourceConverter(Type type) : base(type)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
|
|
|
{
|
|
|
|
|
StandardValuesCollection values = base.GetStandardValues(context);
|
|
|
|
|
ArrayList list = new ArrayList();
|
|
|
|
|
int count = values.Count;
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
string currentItemText = values[i].ToString();
|
2021-04-18 22:27:40 +08:00
|
|
|
|
if (currentItemText != null && !currentItemText.Equals("ListItems"))
|
2020-06-05 21:48:58 +08:00
|
|
|
|
{
|
|
|
|
|
list.Add(values[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new StandardValuesCollection(list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool AcceptsTab
|
|
|
|
|
{
|
|
|
|
|
get => edit.AcceptsTab;
|
|
|
|
|
set => edit.AcceptsTab = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-14 19:35:38 +08:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool EnterAsTab
|
|
|
|
|
{
|
|
|
|
|
get => edit.EnterAsTab;
|
|
|
|
|
set => edit.EnterAsTab = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 21:48:58 +08:00
|
|
|
|
[DefaultValue(true)]
|
|
|
|
|
public bool ShortcutsEnabled
|
|
|
|
|
{
|
|
|
|
|
get => edit.ShortcutsEnabled;
|
|
|
|
|
set => edit.ShortcutsEnabled = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
|
|
|
public bool CanUndo
|
|
|
|
|
{
|
|
|
|
|
get => edit.CanUndo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(true)]
|
|
|
|
|
public bool HideSelection
|
|
|
|
|
{
|
|
|
|
|
get => edit.HideSelection;
|
|
|
|
|
set => edit.HideSelection = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
|
|
|
|
|
MergableProperty(false),
|
|
|
|
|
Localizable(true),
|
|
|
|
|
Editor("System.Windows.Forms.Design.StringArrayEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))
|
|
|
|
|
]
|
|
|
|
|
public string[] Lines
|
|
|
|
|
{
|
|
|
|
|
get => edit.Lines;
|
|
|
|
|
set => edit.Lines = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
|
|
|
public bool Modified
|
|
|
|
|
{
|
|
|
|
|
get => edit.Modified;
|
|
|
|
|
set => edit.Modified = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced),
|
|
|
|
|
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
|
|
|
|
|
]
|
|
|
|
|
public int PreferredHeight
|
|
|
|
|
{
|
|
|
|
|
get => edit.PreferredHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
|
|
|
public string SelectedText
|
|
|
|
|
{
|
|
|
|
|
get => edit.SelectedText;
|
|
|
|
|
set => edit.SelectedText = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
|
|
|
public int SelectionLength
|
|
|
|
|
{
|
|
|
|
|
get => edit.SelectionLength;
|
|
|
|
|
set => edit.SelectionLength = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
|
|
|
public int SelectionStart
|
|
|
|
|
{
|
|
|
|
|
get => edit.SelectionStart;
|
|
|
|
|
set => edit.SelectionStart = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public int TextLength
|
|
|
|
|
{
|
|
|
|
|
get => edit.TextLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AppendText(string text)
|
|
|
|
|
{
|
|
|
|
|
edit.AppendText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearUndo()
|
|
|
|
|
{
|
|
|
|
|
edit.ClearUndo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Copy()
|
|
|
|
|
{
|
|
|
|
|
edit.Copy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Cut()
|
|
|
|
|
{
|
|
|
|
|
edit.Cut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Paste()
|
|
|
|
|
{
|
|
|
|
|
edit.Paste();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public char GetCharFromPosition(Point pt)
|
|
|
|
|
{
|
|
|
|
|
return edit.GetCharFromPosition(pt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetCharIndexFromPosition(Point pt)
|
|
|
|
|
{
|
|
|
|
|
return edit.GetCharIndexFromPosition(pt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetLineFromCharIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
return edit.GetLineFromCharIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Point GetPositionFromCharIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
return edit.GetPositionFromCharIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetFirstCharIndexFromLine(int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
return edit.GetFirstCharIndexFromLine(lineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetFirstCharIndexOfCurrentLine()
|
|
|
|
|
{
|
|
|
|
|
return edit.GetFirstCharIndexOfCurrentLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeselectAll()
|
|
|
|
|
{
|
|
|
|
|
edit.DeselectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Undo()
|
|
|
|
|
{
|
|
|
|
|
edit.Undo();
|
|
|
|
|
}
|
2021-05-12 14:44:39 +08:00
|
|
|
|
|
|
|
|
|
private Image icon;
|
|
|
|
|
[Description("图标"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(null)]
|
|
|
|
|
public Image Icon
|
|
|
|
|
{
|
|
|
|
|
get => icon;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
icon = value;
|
|
|
|
|
SizeChange();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 17:49:55 +08:00
|
|
|
|
private int iconSize = 24;
|
|
|
|
|
[Description("图标大小(方形)"), Category("SunnyUI"), DefaultValue(24)]
|
2021-05-12 14:44:39 +08:00
|
|
|
|
public int IconSize
|
|
|
|
|
{
|
|
|
|
|
get => iconSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-06-01 17:49:55 +08:00
|
|
|
|
iconSize = Math.Min(MinHeight, value);
|
2021-05-12 14:44:39 +08:00
|
|
|
|
SizeChange();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnPaint(e);
|
2021-06-01 17:49:55 +08:00
|
|
|
|
|
|
|
|
|
if (multiline) return;
|
|
|
|
|
if (icon != null)
|
|
|
|
|
{
|
|
|
|
|
e.Graphics.DrawImage(icon, new Rectangle(4, (Height - iconSize) / 2, iconSize, iconSize), new Rectangle(0, 0, icon.Width, icon.Height), GraphicsUnit.Pixel);
|
|
|
|
|
}
|
|
|
|
|
else if (Symbol != 0)
|
|
|
|
|
{
|
2021-07-15 13:54:31 +08:00
|
|
|
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(4 + symbolOffset.X, (Height - SymbolSize) / 2 + 1 + symbolOffset.Y, SymbolSize, SymbolSize), SymbolOffset.X, SymbolOffset.Y);
|
2021-06-01 17:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color _symbolColor = UIFontColor.Primary;
|
|
|
|
|
[DefaultValue(typeof(Color), "48, 48, 48")]
|
|
|
|
|
[Description("字体图标颜色"), Category("SunnyUI")]
|
|
|
|
|
public Color SymbolColor
|
|
|
|
|
{
|
|
|
|
|
get => _symbolColor;
|
|
|
|
|
set
|
2021-05-12 14:44:39 +08:00
|
|
|
|
{
|
2021-06-01 17:49:55 +08:00
|
|
|
|
_symbolColor = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _symbol = 0;
|
|
|
|
|
|
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
|
|
|
[Editor(typeof(UIImagePropertyEditor), typeof(UITypeEditor))]
|
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
[Description("字体图标"), Category("SunnyUI")]
|
|
|
|
|
public int Symbol
|
|
|
|
|
{
|
|
|
|
|
get => _symbol;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_symbol = value;
|
|
|
|
|
SizeChange();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _symbolSize = 24;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(24)]
|
|
|
|
|
[Description("字体图标大小"), Category("SunnyUI")]
|
|
|
|
|
public int SymbolSize
|
|
|
|
|
{
|
|
|
|
|
get => _symbolSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_symbolSize = Math.Max(value, 16);
|
|
|
|
|
_symbolSize = Math.Min(value, MinHeight);
|
|
|
|
|
SizeChange();
|
|
|
|
|
Invalidate();
|
2021-05-12 14:44:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-15 13:54:31 +08:00
|
|
|
|
|
|
|
|
|
private Point symbolOffset = new Point(0, 0);
|
|
|
|
|
|
|
|
|
|
[DefaultValue(typeof(Point), "0, 0")]
|
|
|
|
|
[Description("字体图标的偏移位置"), Category("SunnyUI")]
|
|
|
|
|
public Point SymbolOffset
|
|
|
|
|
{
|
|
|
|
|
get => symbolOffset;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
symbolOffset = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|