!40 UITextBox、UIDropControl细节完善

Merge pull request !40 from wpfly/master
This commit is contained in:
Sunny 2021-05-28 14:54:53 +08:00 committed by Gitee
commit b1543067ae
2 changed files with 67 additions and 11 deletions

View File

@ -48,6 +48,7 @@ namespace Sunny.UI
{ {
InitializeComponent(); InitializeComponent();
SetStyleFlags(); SetStyleFlags();
Padding = new Padding(0, 0, 30, 2);
edit.Font = UIFontColor.Font; edit.Font = UIFontColor.Font;
edit.Left = 3; edit.Left = 3;
@ -266,6 +267,16 @@ namespace Sunny.UI
Invalidate(); Invalidate();
} }
protected override void OnPaddingChanged(EventArgs e)
{
if (Padding.Right < 30 || Padding.Bottom < 2)
{
Padding = new Padding(Padding.Left, Padding.Top, Padding.Right < 30 ? 30 : Padding.Right, Padding.Bottom < 2 ? 2 : Padding.Bottom);
}
base.OnPaddingChanged(e);
SizeChange();
}
protected override void OnSizeChanged(EventArgs e) protected override void OnSizeChanged(EventArgs e)
{ {
SizeChange(); SizeChange();
@ -273,15 +284,9 @@ namespace Sunny.UI
private void SizeChange() private void SizeChange()
{ {
TextBox edt = new TextBox();
edt.Font = edit.Font;
edt.Invalidate();
Height = edt.Height;
edt.Dispose();
edit.Top = (Height - edit.Height) / 2; edit.Top = (Height - edit.Height) / 2;
edit.Left = 3; edit.Left = 3 + Padding.Left;
edit.Width = Width - 30; edit.Width = Width - Padding.Left - Padding.Right;
} }
protected override void OnPaintFore(Graphics g, GraphicsPath path) protected override void OnPaintFore(Graphics g, GraphicsPath path)
@ -295,7 +300,6 @@ namespace Sunny.UI
g.DrawRoundRectangle(rectColor, new Rectangle(0, 0, Width, Height), Radius, true); g.DrawRoundRectangle(rectColor, new Rectangle(0, 0, Width, Height), Radius, true);
} }
Padding = new Padding(0, 0, 30, 2);
g.FillRoundRectangle(GetFillColor(), new Rectangle(Width - 27, edit.Top, 25, edit.Height), Radius); g.FillRoundRectangle(GetFillColor(), new Rectangle(Width - 27, edit.Top, 25, edit.Height), Radius);
Color color = GetRectColor(); Color color = GetRectColor();
SizeF sf = g.GetFontImageSize(dropSymbol, 24); SizeF sf = g.GetFontImageSize(dropSymbol, 24);

View File

@ -44,8 +44,10 @@ namespace Sunny.UI
SetStyleFlags(); SetStyleFlags();
CalcEditHeight(); CalcEditHeight();
Height = MinHeight; Height = MinHeight;
iconSize = MinHeight;
ShowText = false; ShowText = false;
Font = UIFontColor.Font; Font = UIFontColor.Font;
Padding = new Padding(0, 0, 0, 0);
edit.Top = (Height - edit.Height) / 2; edit.Top = (Height - edit.Height) / 2;
edit.Left = 4; edit.Left = 4;
@ -330,6 +332,12 @@ namespace Sunny.UI
SizeChange(); SizeChange();
} }
protected override void OnPaddingChanged(EventArgs e)
{
base.OnPaddingChanged(e);
SizeChange();
}
public void SetScrollInfo() public void SetScrollInfo()
{ {
if (bar == null) if (bar == null)
@ -370,8 +378,16 @@ namespace Sunny.UI
if (Height > MaxHeight) Height = MaxHeight; if (Height > MaxHeight) Height = MaxHeight;
edit.Top = (Height - edit.Height) / 2; edit.Top = (Height - edit.Height) / 2;
edit.Left = 4; if (icon == null)
edit.Width = Width - 8; {
edit.Left = 4 + Padding.Left;
edit.Width = Width - 8 - Padding.Left - Padding.Right;
}
else
{
edit.Left = 4 + iconSize + Padding.Left;
edit.Width = Width - 8 - iconSize - Padding.Left - Padding.Right;
}
} }
else else
{ {
@ -807,5 +823,41 @@ namespace Sunny.UI
{ {
edit.Undo(); edit.Undo();
} }
private Image icon;
[Description("图标"), Category("SunnyUI")]
[DefaultValue(null)]
public Image Icon
{
get => icon;
set
{
icon = value;
SizeChange();
Invalidate();
}
}
private int iconSize;
[Description("图标大小(方形)"), Category("SunnyUI")]
public int IconSize
{
get => iconSize;
set
{
iconSize = value;
SizeChange();
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (!multiline && icon != null)
{
e.Graphics.DrawImage(icon, new Rectangle(4, (Height - iconSize) / 2, iconSize, iconSize), new Rectangle(0, 0, iconSize, iconSize), GraphicsUnit.Pixel);
}
}
} }
} }