2020-05-11 21:11:29 +08:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
2023-01-07 18:12:33 +08:00
|
|
|
|
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
2021-02-20 15:45:47 +08:00
|
|
|
|
* 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
|
|
|
|
|
* 文件说明: 输入框
|
2022-01-05 21:57:47 +08:00
|
|
|
|
* 当前版本: V3.1
|
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 重写了水印文字的画法,并增加水印文字颜色
|
2021-09-07 17:46:27 +08:00
|
|
|
|
* 2021-09-07: V3.0.6 增加按钮
|
2021-10-14 22:19:49 +08:00
|
|
|
|
* 2021-10-14: V3.0.8 调整最小高度限制
|
2021-10-15 16:43:26 +08:00
|
|
|
|
* 2021-10-15: V3.0.8 支持修改背景色
|
2022-01-07 14:34:27 +08:00
|
|
|
|
* 2022-01-07: V3.1.0 按钮支持自定义颜色
|
2022-02-16 15:29:08 +08:00
|
|
|
|
* 2022-02-16: V3.1.1 增加了只读的颜色设置
|
2022-03-14 16:48:09 +08:00
|
|
|
|
* 2022-03-14: V3.1.1 增加滚动条的颜色设置
|
2022-04-11 17:53:40 +08:00
|
|
|
|
* 2022-04-11: V3.1.3 增加对按钮设置ToolTip
|
2022-06-10 13:42:49 +08:00
|
|
|
|
* 2022-06-10: V3.1.9 尺寸改变时重绘
|
2022-06-23 10:54:12 +08:00
|
|
|
|
* 2022-06-23: V3.2.0 重写水印文字,解决不同背景色下泛白的问题
|
2022-07-17 20:15:20 +08:00
|
|
|
|
* 2022-07-17: V3.2.1 增加SelectionChanged事件
|
2022-07-28 16:34:25 +08:00
|
|
|
|
* 2022-07-28: V3.2.2 修复了有水印文字时,不响应Click和DoubleClick事件的问题
|
2022-09-05 14:23:16 +08:00
|
|
|
|
* 2022-09-05: V3.2.3 修复了无水印文字时,光标有时不显示的问题
|
2022-09-16 17:38:02 +08:00
|
|
|
|
* 2022-09-16: V3.2.4 支持自定义右键菜单
|
2022-09-16 22:19:21 +08:00
|
|
|
|
* 2022-09-16: V3.2.4 修改右侧Button可能不显示的问题
|
2022-11-03 21:31:40 +08:00
|
|
|
|
* 2022-11-03: V3.2.6 增加了可设置垂直滚动条宽度的属性
|
2022-11-12 22:13:12 +08:00
|
|
|
|
* 2022-11-12: V3.2.8 修改整数、浮点数大小离开判断为实时输入判断
|
2022-11-13 00:06:38 +08:00
|
|
|
|
* 2022-11-12: V3.2.8 删除MaximumEnabled、MinimumEnabled、HasMaximum、HasMinimum属性
|
2022-11-16 21:28:20 +08:00
|
|
|
|
* 2022-11-26: V3.2.9 增加MouseClick,MouseDoubleClick事件
|
2023-02-07 21:24:12 +08:00
|
|
|
|
* 2023-02-07: V3.3.1 增加Tips小红点
|
2023-02-10 21:45:24 +08:00
|
|
|
|
* 2023-02-10: V3.3.2 有水印时,系统响应触摸屏增加了TouchPressClick属性,默认关闭
|
2023-06-14 23:26:09 +08:00
|
|
|
|
* 2023-06-14: V3.3.9 按钮图标位置修正
|
2023-07-16 20:41:30 +08:00
|
|
|
|
* 2023-07-03: V3.3.9 增加Enabled为false时,可修改文字颜色
|
|
|
|
|
* 2023-07-16: V3.4.0 修复了Enabled为false时,PasswordChar失效的问题
|
2023-08-17 23:25:17 +08:00
|
|
|
|
* 2023-08-17: V3.4.1 修复了Enabled为false时,字体大小调整后,文字显示位置的问题
|
2023-08-24 10:41:14 +08:00
|
|
|
|
* 2023-08-24: V3.4.2 修复了Enabled为false时,自定义颜色,文字不显示的问题
|
2023-10-25 17:19:20 +08:00
|
|
|
|
* 2023-10-25: V3.5.1 修复在高DPI下,文字垂直不居中的问题
|
|
|
|
|
* 2023-10-25: V3.5.1 修复在某些字体不显示下划线的问题
|
2023-10-26 21:55:49 +08:00
|
|
|
|
* 2023-10-26: V3.5.1 字体图标增加旋转角度参数SymbolRotate
|
2023-11-16 22:53:00 +08:00
|
|
|
|
* 2023-11-16: V3.5.2 重构主题
|
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();
|
2021-09-07 17:46:27 +08:00
|
|
|
|
private readonly UISymbolButton btn = new UISymbolButton();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
|
|
|
|
public UITextBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2022-02-07 10:59:32 +08:00
|
|
|
|
InitializeComponentEnd = true;
|
2022-06-10 13:42:49 +08:00
|
|
|
|
SetStyleFlags(true, true, true);
|
2022-01-29 16:30:00 +08:00
|
|
|
|
|
2020-06-05 21:48:58 +08:00
|
|
|
|
ShowText = false;
|
2021-10-14 22:19:49 +08:00
|
|
|
|
MinimumSize = new Size(1, 16);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
2023-10-25 17:19:20 +08:00
|
|
|
|
edit.AutoSize = true;
|
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;
|
2022-07-17 20:15:20 +08:00
|
|
|
|
edit.SelectionChanged += Edit_SelectionChanged;
|
2022-11-16 21:28:20 +08:00
|
|
|
|
edit.MouseClick += Edit_MouseClick;
|
|
|
|
|
edit.MouseDoubleClick += Edit_MouseDoubleClick;
|
2023-10-25 17:19:20 +08:00
|
|
|
|
edit.SizeChanged += Edit_SizeChanged;
|
|
|
|
|
|
2021-09-07 17:46:27 +08:00
|
|
|
|
btn.Parent = this;
|
|
|
|
|
btn.Visible = false;
|
|
|
|
|
btn.Text = "";
|
2022-02-26 10:53:40 +08:00
|
|
|
|
btn.Symbol = 361761;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
btn.Top = 1;
|
|
|
|
|
btn.Height = 25;
|
|
|
|
|
btn.Width = 29;
|
2021-10-15 16:43:26 +08:00
|
|
|
|
btn.BackColor = Color.Transparent;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
btn.Click += Btn_Click;
|
2021-10-15 16:43:26 +08:00
|
|
|
|
btn.Radius = 3;
|
2023-10-26 21:55:49 +08:00
|
|
|
|
btn.SymbolOffset = new Point(-1, 1);
|
2021-09-07 17:46:27 +08:00
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edit.Invalidate();
|
|
|
|
|
Controls.Add(edit);
|
|
|
|
|
fillColor = Color.White;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
|
|
|
|
|
bar.Parent = this;
|
|
|
|
|
bar.Dock = DockStyle.None;
|
|
|
|
|
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
|
|
|
|
|
2023-10-26 21:55:49 +08:00
|
|
|
|
lastEditHeight = edit.Height;
|
2023-10-25 22:30:43 +08:00
|
|
|
|
Width = 150;
|
|
|
|
|
Height = 29;
|
|
|
|
|
|
2020-07-20 21:29:33 +08:00
|
|
|
|
editCursor = Cursor;
|
2020-07-27 23:17:52 +08:00
|
|
|
|
TextAlignmentChange += UITextBox_TextAlignmentChange;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 17:19:20 +08:00
|
|
|
|
int lastEditHeight = -1;
|
|
|
|
|
private void Edit_SizeChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (lastEditHeight != edit.Height)
|
|
|
|
|
{
|
|
|
|
|
lastEditHeight = edit.Height;
|
|
|
|
|
SizeChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 15:43:13 +08:00
|
|
|
|
public override void SetDPIScale()
|
|
|
|
|
{
|
|
|
|
|
base.SetDPIScale();
|
|
|
|
|
if (DesignMode) return;
|
|
|
|
|
if (!UIDPIScale.NeedSetDPIFont()) return;
|
|
|
|
|
|
|
|
|
|
edit.SetDPIScale();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 21:45:24 +08:00
|
|
|
|
[Description("开启后可响应某些触屏的点击事件"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool TouchPressClick
|
|
|
|
|
{
|
|
|
|
|
get => edit.TouchPressClick;
|
|
|
|
|
set => edit.TouchPressClick = value;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 21:24:12 +08:00
|
|
|
|
private UIButton tipsBtn;
|
|
|
|
|
public void SetTipsText(ToolTip toolTip, string text)
|
|
|
|
|
{
|
|
|
|
|
if (tipsBtn == null)
|
|
|
|
|
{
|
|
|
|
|
tipsBtn = new UIButton();
|
|
|
|
|
tipsBtn.Cursor = System.Windows.Forms.Cursors.Hand;
|
2023-08-28 15:19:29 +08:00
|
|
|
|
tipsBtn.Size = new System.Drawing.Size(6, 6);
|
2023-02-07 21:24:12 +08:00
|
|
|
|
tipsBtn.Style = Sunny.UI.UIStyle.Red;
|
|
|
|
|
tipsBtn.StyleCustomMode = true;
|
|
|
|
|
tipsBtn.Text = "";
|
|
|
|
|
tipsBtn.Click += TipsBtn_Click;
|
|
|
|
|
|
|
|
|
|
Controls.Add(tipsBtn);
|
2023-08-28 15:19:29 +08:00
|
|
|
|
tipsBtn.Location = new System.Drawing.Point(Width - 8, 2);
|
2023-02-07 21:24:12 +08:00
|
|
|
|
tipsBtn.BringToFront();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toolTip.SetToolTip(tipsBtn, text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event EventHandler TipsClick;
|
|
|
|
|
private void TipsBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TipsClick?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseTips()
|
|
|
|
|
{
|
|
|
|
|
if (tipsBtn != null)
|
|
|
|
|
{
|
|
|
|
|
tipsBtn.Click -= TipsBtn_Click;
|
|
|
|
|
tipsBtn.Dispose();
|
|
|
|
|
tipsBtn = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 21:28:20 +08:00
|
|
|
|
public new event EventHandler MouseDoubleClick;
|
|
|
|
|
public new event EventHandler MouseClick;
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseDoubleClick?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseClick?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 21:31:40 +08:00
|
|
|
|
private int scrollBarWidth = 0;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(0), Category("SunnyUI"), Description("垂直滚动条宽度,最小为原生滚动条宽度")]
|
|
|
|
|
public int ScrollBarWidth
|
|
|
|
|
{
|
|
|
|
|
get => scrollBarWidth;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
scrollBarWidth = value;
|
|
|
|
|
SetScrollInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int scrollBarHandleWidth = 6;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(6), Category("SunnyUI"), Description("垂直滚动条滑块宽度,最小为原生滚动条宽度")]
|
|
|
|
|
public int ScrollBarHandleWidth
|
|
|
|
|
{
|
|
|
|
|
get => scrollBarHandleWidth;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
scrollBarHandleWidth = value;
|
|
|
|
|
if (bar != null) bar.FillWidth = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-17 20:15:20 +08:00
|
|
|
|
private void Edit_SelectionChanged(object sender, UITextBoxSelectionArgs e)
|
|
|
|
|
{
|
|
|
|
|
SelectionChanged?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event OnSelectionChanged SelectionChanged;
|
|
|
|
|
|
2022-04-11 17:53:40 +08:00
|
|
|
|
public void SetButtonToolTip(ToolTip toolTip, string tipText)
|
|
|
|
|
{
|
|
|
|
|
toolTip.SetToolTip(btn, tipText);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 17:38:02 +08:00
|
|
|
|
protected override void OnContextMenuStripChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnContextMenuStripChanged(e);
|
2022-09-16 22:19:21 +08:00
|
|
|
|
if (edit != null) edit.ContextMenuStrip = ContextMenuStrip;
|
2022-09-16 17:38:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 16:43:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("填充颜色,当值为背景色或透明色或空值则不填充"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(typeof(Color), "White")]
|
|
|
|
|
public new Color FillColor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return fillColor;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (fillColor != value)
|
|
|
|
|
{
|
|
|
|
|
fillColor = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterSetFillColor(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 14:20:44 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体只读颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "109, 109, 103")]
|
2022-02-16 14:20:44 +08:00
|
|
|
|
public Color ForeReadOnlyColor
|
|
|
|
|
{
|
|
|
|
|
get => foreReadOnlyColor;
|
|
|
|
|
set => SetForeReadOnlyColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 边框只读颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "173, 178, 181")]
|
2022-02-16 14:20:44 +08:00
|
|
|
|
public Color RectReadOnlyColor
|
|
|
|
|
{
|
|
|
|
|
get => rectReadOnlyColor;
|
|
|
|
|
set => SetRectReadOnlyColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充只读颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "244, 244, 244")]
|
2022-02-16 14:20:44 +08:00
|
|
|
|
public Color FillReadOnlyColor
|
|
|
|
|
{
|
|
|
|
|
get => fillReadOnlyColor;
|
|
|
|
|
set => SetFillReadOnlyColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 17:46:27 +08:00
|
|
|
|
private void Btn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ButtonClick?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event EventHandler ButtonClick;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(29), Category("SunnyUI"), Description("按钮宽度")]
|
|
|
|
|
public int ButtonWidth { get => btn.Width; set { btn.Width = Math.Max(20, value); SizeChange(); } }
|
|
|
|
|
|
2022-09-16 22:19:21 +08:00
|
|
|
|
private bool showButton = false;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
[DefaultValue(false), Category("SunnyUI"), Description("显示按钮")]
|
|
|
|
|
public bool ShowButton
|
|
|
|
|
{
|
2022-09-16 22:19:21 +08:00
|
|
|
|
get => showButton;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2022-09-16 22:19:21 +08:00
|
|
|
|
showButton = !multiline && value;
|
|
|
|
|
if (btn.IsValid()) btn.Visible = showButton;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
SizeChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Edit_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseLeave?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 需要额外设置ToolTip的控件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>控件</returns>
|
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-09-06 09:52:33 +08:00
|
|
|
|
public new event MouseEventHandler MouseDown;
|
|
|
|
|
public new event MouseEventHandler MouseUp;
|
|
|
|
|
public new event MouseEventHandler MouseMove;
|
|
|
|
|
public new event EventHandler GotFocus;
|
|
|
|
|
public new event EventHandler LostFocus;
|
|
|
|
|
public new event CancelEventHandler Validating;
|
2021-07-05 22:09:10 +08:00
|
|
|
|
public new event EventHandler Validated;
|
2021-09-06 09:52:33 +08:00
|
|
|
|
public new event EventHandler MouseLeave;
|
|
|
|
|
public new event EventHandler DoubleClick;
|
|
|
|
|
public new event EventHandler Click;
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public new event EventHandler TextChanged;
|
|
|
|
|
public new event KeyEventHandler KeyDown;
|
|
|
|
|
public new event KeyEventHandler KeyUp;
|
|
|
|
|
public new event KeyPressEventHandler KeyPress;
|
|
|
|
|
public new event EventHandler Leave;
|
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);
|
2022-02-16 15:29:08 +08:00
|
|
|
|
edit.BackColor = GetFillColor();
|
2023-08-24 10:41:14 +08:00
|
|
|
|
|
|
|
|
|
edit.Visible = true;
|
2023-08-18 09:50:11 +08:00
|
|
|
|
edit.Enabled = Enabled;
|
2023-08-24 10:41:14 +08:00
|
|
|
|
if (!Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (NeedDrawDisabledText) edit.Visible = false;
|
|
|
|
|
}
|
2023-08-18 09:50:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 10:41:14 +08:00
|
|
|
|
private bool NeedDrawDisabledText => !Enabled && StyleCustomMode && (ForeDisableColor != Color.FromArgb(109, 109, 103) || FillDisableColor != Color.FromArgb(244, 244, 244));
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-10-16 22:33:10 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 22:19:21 +08:00
|
|
|
|
private bool multiline = false;
|
2020-06-03 12:16:27 +08:00
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 10:54:12 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "Gray")]
|
|
|
|
|
[Description("水印文字激活颜色"), Category("SunnyUI")]
|
|
|
|
|
public Color WatermarkActiveColor
|
|
|
|
|
{
|
|
|
|
|
get => edit.WaterMarkActiveForeColor;
|
|
|
|
|
set => edit.WaterMarkActiveForeColor = 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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-12 22:13:12 +08:00
|
|
|
|
internal void CheckMaxMin()
|
2020-05-11 21:11:29 +08:00
|
|
|
|
{
|
|
|
|
|
edit.CheckMaxMin();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载字体变更
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnFontChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnFontChanged(e);
|
2023-08-30 15:43:13 +08:00
|
|
|
|
|
2023-10-25 17:19:20 +08:00
|
|
|
|
if (DefaultFontSize < 0 && edit != null)
|
2023-10-26 21:55:49 +08:00
|
|
|
|
{
|
2023-10-25 17:19:20 +08:00
|
|
|
|
edit.Font = this.Font;
|
2023-10-26 21:55:49 +08:00
|
|
|
|
}
|
2023-08-30 15:43:13 +08:00
|
|
|
|
|
2020-06-06 23:08:16 +08:00
|
|
|
|
Invalidate();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载控件尺寸变更
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnSizeChanged(EventArgs e)
|
|
|
|
|
{
|
2022-06-10 13:42:49 +08:00
|
|
|
|
base.OnSizeChanged(e);
|
2023-10-25 17:19:20 +08:00
|
|
|
|
|
|
|
|
|
if (!NoNeedChange)
|
|
|
|
|
{
|
|
|
|
|
SizeChange();
|
|
|
|
|
}
|
2023-02-07 21:28:09 +08:00
|
|
|
|
|
|
|
|
|
if (tipsBtn != null)
|
|
|
|
|
{
|
2023-08-28 15:19:29 +08:00
|
|
|
|
tipsBtn.Location = new System.Drawing.Point(Width - 8, 2);
|
2023-02-07 21:28:09 +08:00
|
|
|
|
}
|
2020-05-11 21:11:29 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 17:19:20 +08:00
|
|
|
|
private bool NoNeedChange = false;
|
|
|
|
|
|
2020-06-06 23:08:16 +08:00
|
|
|
|
private void SizeChange()
|
|
|
|
|
{
|
2022-02-07 10:59:32 +08:00
|
|
|
|
if (!InitializeComponentEnd) return;
|
2021-10-15 16:43:26 +08:00
|
|
|
|
if (edit == null) return;
|
|
|
|
|
if (btn == null) return;
|
|
|
|
|
|
2020-06-03 12:16:27 +08:00
|
|
|
|
if (!multiline)
|
|
|
|
|
{
|
2023-10-25 17:19:20 +08:00
|
|
|
|
if (Height < edit.Height + RectSize * 2 + 2)
|
|
|
|
|
{
|
|
|
|
|
NoNeedChange = true;
|
|
|
|
|
Height = edit.Height + RectSize * 2 + 2;
|
|
|
|
|
edit.Top = (Height - edit.Height) / 2;
|
|
|
|
|
NoNeedChange = false;
|
|
|
|
|
}
|
2020-06-06 23:08:16 +08:00
|
|
|
|
|
2023-10-25 22:30:43 +08:00
|
|
|
|
if (edit.Top != (Height - edit.Height) / 2 + 1)
|
2023-10-25 17:19:20 +08:00
|
|
|
|
{
|
2023-10-25 22:30:43 +08:00
|
|
|
|
edit.Top = (Height - edit.Height) / 2 + 1;
|
2023-10-25 17:19:20 +08:00
|
|
|
|
}
|
2021-10-14 22:19:49 +08:00
|
|
|
|
|
2021-06-01 17:49:55 +08:00
|
|
|
|
if (icon == null && Symbol == 0)
|
2021-05-12 14:44:39 +08:00
|
|
|
|
{
|
2023-05-08 13:30:31 +08:00
|
|
|
|
edit.Left = 4;
|
|
|
|
|
edit.Width = Width - 8;
|
2021-05-12 14:44:39 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-01 17:49:55 +08:00
|
|
|
|
if (icon != null)
|
|
|
|
|
{
|
2023-05-08 13:30:31 +08:00
|
|
|
|
edit.Left = 4 + iconSize;
|
|
|
|
|
edit.Width = Width - 8 - iconSize;
|
2021-06-01 17:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Symbol > 0)
|
|
|
|
|
{
|
2023-05-08 13:30:31 +08:00
|
|
|
|
edit.Left = 4 + SymbolSize;
|
|
|
|
|
edit.Width = Width - 8 - SymbolSize;
|
2021-06-01 17:49:55 +08:00
|
|
|
|
}
|
2021-05-12 14:44:39 +08:00
|
|
|
|
}
|
2021-09-07 17:46:27 +08:00
|
|
|
|
|
2021-10-15 16:43:26 +08:00
|
|
|
|
btn.Left = Width - 2 - ButtonWidth;
|
|
|
|
|
btn.Top = 2;
|
|
|
|
|
btn.Height = Height - 4;
|
|
|
|
|
|
2021-09-07 17:46:27 +08:00
|
|
|
|
if (ShowButton)
|
|
|
|
|
{
|
2021-10-15 16:43:26 +08:00
|
|
|
|
edit.Width = edit.Width - btn.Width - 3;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
}
|
2020-06-03 12:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-09-07 17:46:27 +08:00
|
|
|
|
btn.Visible = false;
|
2020-06-03 12:16:27 +08:00
|
|
|
|
edit.Top = 3;
|
|
|
|
|
edit.Height = Height - 6;
|
2023-10-25 17:31:51 +08:00
|
|
|
|
edit.Left = 4;
|
|
|
|
|
edit.Width = Width - 8;
|
2021-09-07 17:46:27 +08:00
|
|
|
|
|
2023-11-16 22:53:00 +08:00
|
|
|
|
int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 2, ScrollBarWidth);
|
2020-06-03 14:10:28 +08:00
|
|
|
|
bar.Top = 2;
|
2023-11-16 22:53:00 +08:00
|
|
|
|
bar.Width = barWidth + 1;
|
|
|
|
|
bar.Left = Width - barWidth - 3;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2022-02-16 15:29:08 +08:00
|
|
|
|
get => isReadOnly;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2022-02-16 15:29:08 +08:00
|
|
|
|
isReadOnly = value;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
edit.ReadOnly = value;
|
2022-02-16 15:29:08 +08:00
|
|
|
|
edit.BackColor = GetFillColor();
|
|
|
|
|
Invalidate();
|
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")]
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(2147483647D)]
|
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")]
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(-2147483648D)]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public double Minimum
|
|
|
|
|
{
|
|
|
|
|
get => edit.MinValue;
|
|
|
|
|
set => edit.MinValue = 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)]
|
2022-08-01 15:33:00 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 17:49:45 +08:00
|
|
|
|
[Description("浮点数,显示文字小数位数"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(2)]
|
|
|
|
|
public int DecimalPlaces
|
|
|
|
|
{
|
2022-07-28 16:53:09 +08:00
|
|
|
|
get => edit.DecLength;
|
|
|
|
|
set => edit.DecLength = Math.Max(value, 0);
|
2022-01-28 17:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue(false)]
|
2022-08-01 15:33:00 +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 == "";
|
|
|
|
|
|
2022-06-27 17:06:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载鼠标按下事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">鼠标参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 23:27:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置主题样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uiColor">主题样式</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public override void SetStyleColor(UIBaseStyle uiColor)
|
|
|
|
|
{
|
|
|
|
|
base.SetStyleColor(uiColor);
|
2021-10-15 16:43:26 +08:00
|
|
|
|
|
|
|
|
|
fillColor = uiColor.EditorBackColor;
|
2022-02-16 15:29:08 +08:00
|
|
|
|
foreColor = UIFontColor.Primary;
|
|
|
|
|
edit.BackColor = GetFillColor();
|
|
|
|
|
edit.ForeColor = GetForeColor();
|
2023-07-03 13:40:37 +08:00
|
|
|
|
edit.ForeDisableColor = uiColor.ForeDisableColor;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
|
2023-11-16 22:53:00 +08:00
|
|
|
|
if (bar != null && bar.Style == UIStyle.Inherited)
|
2020-06-03 14:10:28 +08:00
|
|
|
|
{
|
|
|
|
|
bar.ForeColor = uiColor.PrimaryColor;
|
|
|
|
|
bar.HoverColor = uiColor.ButtonFillHoverColor;
|
|
|
|
|
bar.PressColor = uiColor.ButtonFillPressColor;
|
2021-10-15 16:43:26 +08:00
|
|
|
|
bar.FillColor = fillColor;
|
2022-03-14 16:45:40 +08:00
|
|
|
|
scrollBarColor = uiColor.PrimaryColor;
|
|
|
|
|
scrollBarBackColor = fillColor;
|
2020-06-03 14:10:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-17 23:07:19 +08:00
|
|
|
|
if (btn != null && btn.Style == UIStyle.Inherited)
|
2022-01-07 14:34:27 +08:00
|
|
|
|
{
|
|
|
|
|
btn.ForeColor = uiColor.ButtonForeColor;
|
|
|
|
|
btn.FillColor = uiColor.ButtonFillColor;
|
|
|
|
|
btn.RectColor = uiColor.RectColor;
|
|
|
|
|
|
|
|
|
|
btn.FillHoverColor = uiColor.ButtonFillHoverColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
btn.RectHoverColor = uiColor.ButtonRectHoverColor;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
btn.ForeHoverColor = uiColor.ButtonForeHoverColor;
|
|
|
|
|
|
|
|
|
|
btn.FillPressColor = uiColor.ButtonFillPressColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
btn.RectPressColor = uiColor.ButtonRectPressColor;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
btn.ForePressColor = uiColor.ButtonForePressColor;
|
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 22:53:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 滚动条主题样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")]
|
|
|
|
|
public bool ScrollBarStyleInherited
|
|
|
|
|
{
|
|
|
|
|
get => bar != null && bar.Style == UIStyle.Inherited;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
if (bar != null) bar.Style = UIStyle.Inherited;
|
|
|
|
|
scrollBarColor = UIStyles.Blue.PrimaryColor;
|
|
|
|
|
scrollBarBackColor = UIStyles.Blue.EditorBackColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 13:40:37 +08:00
|
|
|
|
protected override void SetForeDisableColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.SetForeDisableColor(color);
|
|
|
|
|
edit.ForeDisableColor = color;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:45:40 +08:00
|
|
|
|
private Color scrollBarColor = Color.FromArgb(80, 160, 255);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
|
|
|
|
/// </summary>
|
2022-05-26 11:03:06 +08:00
|
|
|
|
[Description("滚动条填充颜色"), Category("SunnyUI")]
|
2022-03-14 16:45:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
|
|
|
|
public Color ScrollBarColor
|
|
|
|
|
{
|
|
|
|
|
get => scrollBarColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
scrollBarColor = value;
|
|
|
|
|
bar.HoverColor = bar.PressColor = bar.ForeColor = value;
|
2023-11-16 22:53:00 +08:00
|
|
|
|
bar.Style = UIStyle.Custom;
|
2022-03-14 16:45:40 +08:00
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color scrollBarBackColor = Color.White;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
|
|
|
|
/// </summary>
|
2022-05-26 11:03:06 +08:00
|
|
|
|
[Description("滚动条背景颜色"), Category("SunnyUI")]
|
2022-03-14 16:45:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "White")]
|
|
|
|
|
public Color ScrollBarBackColor
|
|
|
|
|
{
|
|
|
|
|
get => scrollBarBackColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
scrollBarBackColor = value;
|
|
|
|
|
bar.FillColor = value;
|
2023-11-16 22:53:00 +08:00
|
|
|
|
bar.Style = UIStyle.Custom;
|
2022-03-14 16:45:40 +08:00
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void AfterSetForeColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.AfterSetForeColor(color);
|
2022-02-16 15:29:08 +08:00
|
|
|
|
edit.ForeColor = GetForeColor();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AfterSetFillColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.AfterSetFillColor(color);
|
2022-02-16 15:29:08 +08:00
|
|
|
|
edit.BackColor = GetFillColor();
|
2022-03-14 16:45:40 +08:00
|
|
|
|
bar.FillColor = color;
|
2022-02-16 15:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AfterSetFillReadOnlyColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.AfterSetFillReadOnlyColor(color);
|
|
|
|
|
edit.BackColor = GetFillColor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AfterSetForeReadOnlyColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
base.AfterSetForeReadOnlyColor(color);
|
|
|
|
|
edit.ForeColor = GetForeColor();
|
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
|
|
|
|
|
{
|
2022-02-07 12:09:42 +08:00
|
|
|
|
iconSize = Math.Min(UIGlobal.EditorMinHeight, value);
|
2021-05-12 14:44:39 +08:00
|
|
|
|
SizeChange();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载绘图
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">绘图参数</param>
|
2021-05-12 14:44:39 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-10-26 21:55:49 +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, SymbolRotate);
|
2021-06-01 17:49:55 +08:00
|
|
|
|
}
|
2023-08-17 23:25:17 +08:00
|
|
|
|
|
2023-11-06 14:08:09 +08:00
|
|
|
|
if (Text.IsValid() && NeedDrawDisabledText)
|
2023-08-17 23:25:17 +08:00
|
|
|
|
{
|
|
|
|
|
string text = Text;
|
|
|
|
|
if (PasswordChar > 0)
|
|
|
|
|
{
|
|
|
|
|
text = PasswordChar.ToString().Repeat(text.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContentAlignment textAlign = ContentAlignment.MiddleLeft;
|
|
|
|
|
if (TextAlignment == ContentAlignment.TopCenter || TextAlignment == ContentAlignment.MiddleCenter || TextAlignment == ContentAlignment.BottomCenter)
|
|
|
|
|
textAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
|
|
|
|
|
if (TextAlignment == ContentAlignment.TopRight || TextAlignment == ContentAlignment.MiddleRight || TextAlignment == ContentAlignment.BottomRight)
|
|
|
|
|
textAlign = ContentAlignment.MiddleRight;
|
|
|
|
|
|
2023-08-24 10:41:14 +08:00
|
|
|
|
e.Graphics.DrawString(text, edit.Font, ForeDisableColor, edit.Bounds, textAlign);
|
2023-08-17 23:25:17 +08:00
|
|
|
|
}
|
2021-06-01 17:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color _symbolColor = UIFontColor.Primary;
|
2022-06-23 23:27:55 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体图标颜色
|
|
|
|
|
/// </summary>
|
2021-06-01 17:49:55 +08:00
|
|
|
|
[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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-16 22:33:10 +08:00
|
|
|
|
private int _symbol;
|
2021-06-01 17:49:55 +08:00
|
|
|
|
|
2022-06-23 23:27:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体图标
|
|
|
|
|
/// </summary>
|
2021-06-01 17:49:55 +08:00
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
2022-01-18 11:29:57 +08:00
|
|
|
|
[Editor("Sunny.UI.UIImagePropertyEditor, " + AssemblyRefEx.SystemDesign, typeof(UITypeEditor))]
|
2021-06-01 17:49:55 +08:00
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
[Description("字体图标"), Category("SunnyUI")]
|
|
|
|
|
public int Symbol
|
|
|
|
|
{
|
|
|
|
|
get => _symbol;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_symbol = value;
|
|
|
|
|
SizeChange();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _symbolSize = 24;
|
|
|
|
|
|
2022-06-23 23:27:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体图标大小
|
|
|
|
|
/// </summary>
|
2021-06-01 17:49:55 +08:00
|
|
|
|
[DefaultValue(24)]
|
|
|
|
|
[Description("字体图标大小"), Category("SunnyUI")]
|
|
|
|
|
public int SymbolSize
|
|
|
|
|
{
|
|
|
|
|
get => _symbolSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_symbolSize = Math.Max(value, 16);
|
2022-02-07 12:09:42 +08:00
|
|
|
|
_symbolSize = Math.Min(value, UIGlobal.EditorMaxHeight);
|
2021-06-01 17:49:55 +08:00
|
|
|
|
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);
|
|
|
|
|
|
2022-06-23 23:27:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体图标的偏移位置
|
|
|
|
|
/// </summary>
|
2021-07-15 13:54:31 +08:00
|
|
|
|
[DefaultValue(typeof(Point), "0, 0")]
|
|
|
|
|
[Description("字体图标的偏移位置"), Category("SunnyUI")]
|
|
|
|
|
public Point SymbolOffset
|
|
|
|
|
{
|
|
|
|
|
get => symbolOffset;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
symbolOffset = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-07 17:46:27 +08:00
|
|
|
|
|
2023-10-26 21:55:49 +08:00
|
|
|
|
private int _symbolRotate = 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体图标旋转角度
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
[Description("字体图标旋转角度"), Category("SunnyUI")]
|
|
|
|
|
public int SymbolRotate
|
|
|
|
|
{
|
|
|
|
|
get => _symbolRotate;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_symbolRotate != value)
|
|
|
|
|
{
|
|
|
|
|
_symbolRotate = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 17:46:27 +08:00
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
2022-01-18 11:29:57 +08:00
|
|
|
|
[Editor("Sunny.UI.UIImagePropertyEditor, " + AssemblyRefEx.SystemDesign, typeof(UITypeEditor))]
|
2022-02-26 10:53:40 +08:00
|
|
|
|
[DefaultValue(361761)]
|
2021-09-07 17:46:27 +08:00
|
|
|
|
[Description("按钮字体图标"), Category("SunnyUI")]
|
|
|
|
|
public int ButtonSymbol
|
|
|
|
|
{
|
|
|
|
|
get => btn.Symbol;
|
|
|
|
|
set => btn.Symbol = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(24)]
|
|
|
|
|
[Description("按钮字体图标大小"), Category("SunnyUI")]
|
|
|
|
|
public int ButtonSymbolSize
|
|
|
|
|
{
|
|
|
|
|
get => btn.SymbolSize;
|
|
|
|
|
set => btn.SymbolSize = value;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 21:55:49 +08:00
|
|
|
|
[DefaultValue(typeof(Point), "-1, 1")]
|
2021-09-07 17:46:27 +08:00
|
|
|
|
[Description("按钮字体图标的偏移位置"), Category("SunnyUI")]
|
|
|
|
|
public Point ButtonSymbolOffset
|
|
|
|
|
{
|
|
|
|
|
get => btn.SymbolOffset;
|
|
|
|
|
set => btn.SymbolOffset = value;
|
|
|
|
|
}
|
2022-01-07 14:34:27 +08:00
|
|
|
|
|
2023-10-26 21:55:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体图标旋转角度
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
[Description("按钮字体图标旋转角度"), Category("SunnyUI")]
|
|
|
|
|
public int ButtonSymbolRotate
|
|
|
|
|
{
|
|
|
|
|
get => btn.SymbolRotate;
|
|
|
|
|
set => btn.SymbolRotate = value;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 14:34:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("按钮填充颜色"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
|
|
|
|
public Color ButtonFillColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.FillColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
btn.FillColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体颜色
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("按钮字体颜色"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(typeof(Color), "White")]
|
|
|
|
|
public Color ButtonForeColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.ForeColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-01-10 19:39:10 +08:00
|
|
|
|
btn.SymbolColor = btn.ForeColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 边框颜色
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("按钮边框颜色"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
|
|
|
|
public Color ButtonRectColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.RectColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
btn.RectColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "115, 179, 255"), Category("SunnyUI")]
|
2022-01-07 14:34:27 +08:00
|
|
|
|
[Description("按钮鼠标移上时填充颜色")]
|
|
|
|
|
public Color ButtonFillHoverColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.FillHoverColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
btn.FillHoverColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(typeof(Color), "White"), Category("SunnyUI")]
|
|
|
|
|
[Description("按钮鼠标移上时字体颜色")]
|
|
|
|
|
public Color ButtonForeHoverColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.ForeHoverColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-01-12 11:57:28 +08:00
|
|
|
|
btn.SymbolHoverColor = btn.ForeHoverColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "115, 179, 255"), Category("SunnyUI")]
|
2022-01-07 14:34:27 +08:00
|
|
|
|
[Description("鼠标移上时边框颜色")]
|
|
|
|
|
public Color ButtonRectHoverColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.RectHoverColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
btn.RectHoverColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "64, 128, 204"), Category("SunnyUI")]
|
2022-01-07 14:34:27 +08:00
|
|
|
|
[Description("按钮鼠标按下时填充颜色")]
|
|
|
|
|
public Color ButtonFillPressColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.FillPressColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
btn.FillPressColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(typeof(Color), "White"), Category("SunnyUI")]
|
|
|
|
|
[Description("按钮鼠标按下时字体颜色")]
|
|
|
|
|
public Color ButtonForePressColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.ForePressColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-01-12 11:57:28 +08:00
|
|
|
|
btn.SymbolPressColor = btn.ForePressColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "64, 128, 204"), Category("SunnyUI")]
|
2022-01-07 14:34:27 +08:00
|
|
|
|
[Description("按钮鼠标按下时边框颜色")]
|
|
|
|
|
public Color ButtonRectPressColor
|
|
|
|
|
{
|
|
|
|
|
get => btn.RectPressColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
btn.RectPressColor = value;
|
2023-11-17 23:07:19 +08:00
|
|
|
|
btn.Style = UIStyle.Custom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 滚动条主题样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")]
|
|
|
|
|
public bool ButtonStyleInherited
|
|
|
|
|
{
|
|
|
|
|
get => btn != null && btn.Style == UIStyle.Inherited;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value && btn != null)
|
|
|
|
|
{
|
|
|
|
|
btn.Style = UIStyle.Inherited;
|
|
|
|
|
}
|
2022-01-07 14:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|