* UITextBox:增加Multiline属性,增加滚动条
This commit is contained in:
parent
f43d1ce851
commit
ecc4123106
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
@ -17,6 +17,7 @@
|
||||
* 创建日期: 2020-01-01
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
* 2020-06-03: V2.2.5 增加多行,增加滚动条
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -32,6 +33,7 @@ namespace Sunny.UI
|
||||
public sealed partial class UITextBox : UIPanel
|
||||
{
|
||||
private readonly UIEdit edit = new UIEdit();
|
||||
private readonly UIScrollBar bar = new UIScrollBar();
|
||||
|
||||
public UITextBox()
|
||||
{
|
||||
@ -47,11 +49,63 @@ namespace Sunny.UI
|
||||
edit.TextChanged += EditTextChanged;
|
||||
edit.KeyUp += EditOnKeyUp;
|
||||
edit.KeyPress += EditOnKeyPress;
|
||||
edit.MouseEnter += Edit_MouseEnter;
|
||||
|
||||
edit.Invalidate();
|
||||
Controls.Add(edit);
|
||||
fillColor = Color.White;
|
||||
Width = 150;
|
||||
|
||||
bar.Parent = this;
|
||||
bar.Dock = DockStyle.None;
|
||||
bar.Style = UIStyle.Custom;
|
||||
bar.Visible = false;
|
||||
bar.ValueChanged += Bar_ValueChanged;
|
||||
edit.MouseWheel += OnMouseWheel;
|
||||
bar.MouseEnter += Bar_MouseEnter;
|
||||
}
|
||||
|
||||
private void Bar_MouseEnter(object sender, EventArgs e)
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
|
||||
private void Edit_MouseEnter(object sender, EventArgs e)
|
||||
{
|
||||
Cursor = Cursors.IBeam;
|
||||
}
|
||||
|
||||
private void OnMouseWheel(object sender, MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
if (bar.Visible)
|
||||
{
|
||||
var si = ScrollBarInfo.GetInfo(Handle);
|
||||
if (e.Delta > 10)
|
||||
{
|
||||
if (si.nPos > 0)
|
||||
{
|
||||
ScrollBarInfo.ScrollUp(Handle);
|
||||
}
|
||||
}
|
||||
else if (e.Delta < -10)
|
||||
{
|
||||
if (si.nPos < si.ScrollMax)
|
||||
{
|
||||
ScrollBarInfo.ScrollDown(Handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetScrollInfo();
|
||||
}
|
||||
|
||||
private void Bar_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (edit != null)
|
||||
{
|
||||
ScrollBarInfo.SetScrollValue(edit.Handle, bar.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool multiline;
|
||||
@ -64,10 +118,31 @@ namespace Sunny.UI
|
||||
{
|
||||
multiline = value;
|
||||
edit.Multiline = value;
|
||||
|
||||
edit.ScrollBars = value ? ScrollBars.Vertical : ScrollBars.None;
|
||||
bar.Visible = multiline;
|
||||
|
||||
SizeChange();
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool WordWarp
|
||||
{
|
||||
get => edit.WordWrap;
|
||||
set => edit.WordWrap = value;
|
||||
}
|
||||
|
||||
public void Select(int start, int length)
|
||||
{
|
||||
edit.Select(start, length);
|
||||
}
|
||||
|
||||
public void ScrollToCaret()
|
||||
{
|
||||
edit.ScrollToCaret();
|
||||
}
|
||||
|
||||
private void EditOnKeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
KeyPress?.Invoke(sender, e);
|
||||
@ -107,6 +182,7 @@ namespace Sunny.UI
|
||||
private void EditTextChanged(object s, EventArgs e)
|
||||
{
|
||||
TextChanged?.Invoke(this, e);
|
||||
SetScrollInfo();
|
||||
}
|
||||
|
||||
protected override void OnFontChanged(EventArgs e)
|
||||
@ -126,6 +202,27 @@ namespace Sunny.UI
|
||||
SizeChange();
|
||||
}
|
||||
|
||||
public void SetScrollInfo()
|
||||
{
|
||||
if (bar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var si = ScrollBarInfo.GetInfo(edit.Handle);
|
||||
if (si.ScrollMax > 0)
|
||||
{
|
||||
bar.Maximum = si.ScrollMax;
|
||||
//bar.Visible = si.ScrollMax > 0 && si.nMax > 0 && si.nPage > 0;
|
||||
bar.Value = si.nPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
bar.Maximum = si.ScrollMax;
|
||||
//bar.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private int MiniHeight;
|
||||
|
||||
private void SizeChange()
|
||||
@ -154,6 +251,13 @@ namespace Sunny.UI
|
||||
edit.Height = Height - 6;
|
||||
edit.Left = 1;
|
||||
edit.Width = Width - 2;
|
||||
bar.Top = 2;
|
||||
bar.Width = ScrollBarInfo.VerticalScrollBarWidth();
|
||||
bar.Left = Width - bar.Width - 1;
|
||||
bar.Height = Height - 4;
|
||||
bar.BringToFront();
|
||||
|
||||
SetScrollInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,6 +424,15 @@ namespace Sunny.UI
|
||||
|
||||
edit.BackColor = fillColor = Color.White;
|
||||
edit.ForeColor = foreColor = UIFontColor.Primary;
|
||||
|
||||
if (bar != null)
|
||||
{
|
||||
bar.ForeColor = uiColor.PrimaryColor;
|
||||
bar.HoverColor = uiColor.ButtonFillHoverColor;
|
||||
bar.PressColor = uiColor.ButtonFillPressColor;
|
||||
bar.FillColor = Color.White;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
+ 增加; - 删除; * 修改
|
||||
|
||||
2020.06.03
|
||||
* UITextBox:增加Multiline属性
|
||||
* UITextBox:增加Multiline属性,增加滚动条
|
||||
|
||||
2020.06.02
|
||||
+ UIDatetimePicker:新增
|
||||
|
Loading…
x
Reference in New Issue
Block a user