* UITextBox: 修正编辑框高度

This commit is contained in:
Sunny 2022-02-07 10:59:32 +08:00
parent b87205d795
commit 7634dedc59
5 changed files with 16 additions and 15 deletions

Binary file not shown.

Binary file not shown.

View File

@ -20,13 +20,10 @@
******************************************************************************/ ******************************************************************************/
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
@ -38,9 +35,12 @@ namespace Sunny.UI
public UIIPTextBox() public UIIPTextBox()
{ {
InitializeComponent(); InitializeComponent();
InitializeComponentEnd = true;
SetStyleFlags(); SetStyleFlags();
ShowText = false; ShowText = false;
Width = 150;
Height = 29;
UIIPTextBox_SizeChanged(null, null); UIIPTextBox_SizeChanged(null, null);
foreach (TextBox txt in Controls.OfType<TextBox>()) foreach (TextBox txt in Controls.OfType<TextBox>())
@ -53,6 +53,9 @@ namespace Sunny.UI
} }
} }
const int MinHeight = 20;
const int MaxHeight = 60;
private void Txt_Leave(object sender, EventArgs e) private void Txt_Leave(object sender, EventArgs e)
{ {
TextBox t = (TextBox)sender; TextBox t = (TextBox)sender;
@ -400,9 +403,6 @@ namespace Sunny.UI
txt3.Left = txt2.Right + 5; txt3.Left = txt2.Right + 5;
txt4.Left = txt3.Right + 5; txt4.Left = txt3.Right + 5;
int MinHeight = txt1.PreferredHeight + RectSize * 2;
int MaxHeight = txt1.PreferredHeight * 2;
if (Height < MinHeight) Height = MinHeight; if (Height < MinHeight) Height = MinHeight;
if (Height > MaxHeight) Height = MaxHeight; if (Height > MaxHeight) Height = MaxHeight;
@ -417,6 +417,7 @@ namespace Sunny.UI
protected override void OnFontChanged(EventArgs e) protected override void OnFontChanged(EventArgs e)
{ {
base.OnFontChanged(e); base.OnFontChanged(e);
if (!InitializeComponentEnd) return;
if (txt1 == null || txt2 == null || txt3 == null || txt4 == null) return; if (txt1 == null || txt2 == null || txt3 == null || txt4 == null) return;
txt1.Font = txt2.Font = txt3.Font = txt4.Font = Font; txt1.Font = txt2.Font = txt3.Font = txt4.Font = Font;
UIIPTextBox_SizeChanged(null, null); UIIPTextBox_SizeChanged(null, null);

View File

@ -45,6 +45,7 @@ namespace Sunny.UI
protected Color rectColor = UIStyles.GetStyleColor(UIStyle.Blue).RectColor; protected Color rectColor = UIStyles.GetStyleColor(UIStyle.Blue).RectColor;
protected Color fillColor = UIStyles.GetStyleColor(UIStyle.Blue).PlainColor; protected Color fillColor = UIStyles.GetStyleColor(UIStyle.Blue).PlainColor;
protected Color foreColor = UIStyles.GetStyleColor(UIStyle.Blue).PanelForeColor; protected Color foreColor = UIStyles.GetStyleColor(UIStyle.Blue).PanelForeColor;
protected bool InitializeComponentEnd;
public UIPanel() public UIPanel()
{ {

View File

@ -49,9 +49,11 @@ namespace Sunny.UI
private readonly UIScrollBar bar = new UIScrollBar(); private readonly UIScrollBar bar = new UIScrollBar();
private readonly UISymbolButton btn = new UISymbolButton(); private readonly UISymbolButton btn = new UISymbolButton();
public UITextBox() public UITextBox()
{ {
InitializeComponent(); InitializeComponent();
InitializeComponentEnd = true;
SetStyleFlags(); SetStyleFlags();
ShowText = false; ShowText = false;
@ -59,6 +61,9 @@ namespace Sunny.UI
Padding = new Padding(0); Padding = new Padding(0);
MinimumSize = new Size(1, 16); MinimumSize = new Size(1, 16);
Width = 150;
Height = 29;
edit.AutoSize = false; edit.AutoSize = false;
edit.Top = (Height - edit.Height) / 2; edit.Top = (Height - edit.Height) / 2;
edit.Left = 4; edit.Left = 4;
@ -97,8 +102,6 @@ namespace Sunny.UI
edit.Invalidate(); edit.Invalidate();
Controls.Add(edit); Controls.Add(edit);
fillColor = Color.White; fillColor = Color.White;
Width = 150;
Height = 29;
bar.Parent = this; bar.Parent = this;
bar.Dock = DockStyle.None; bar.Dock = DockStyle.None;
@ -281,8 +284,6 @@ namespace Sunny.UI
DoubleClick?.Invoke(this, e); DoubleClick?.Invoke(this, e);
} }
private void Edit_Click(object sender, EventArgs e) private void Edit_Click(object sender, EventArgs e)
{ {
Click?.Invoke(this, e); Click?.Invoke(this, e);
@ -502,19 +503,17 @@ namespace Sunny.UI
} }
} }
int MinHeight; const int MinHeight = 20;
int MaxHeight; const int MaxHeight = 60;
private void SizeChange() private void SizeChange()
{ {
if (!InitializeComponentEnd) return;
if (edit == null) return; if (edit == null) return;
if (btn == null) return; if (btn == null) return;
if (!multiline) if (!multiline)
{ {
MinHeight = edit.PreferredHeight + RectSize * 2;
MaxHeight = edit.PreferredHeight * 2;
if (Height < MinHeight) Height = MinHeight; if (Height < MinHeight) Height = MinHeight;
if (Height > MaxHeight) Height = MaxHeight; if (Height > MaxHeight) Height = MaxHeight;