diff --git a/SunnyUI/Controls/DropItem/UIDropControl.cs b/SunnyUI/Controls/DropItem/UIDropControl.cs index 3ab01518..e1c70a0d 100644 --- a/SunnyUI/Controls/DropItem/UIDropControl.cs +++ b/SunnyUI/Controls/DropItem/UIDropControl.cs @@ -48,6 +48,7 @@ namespace Sunny.UI { InitializeComponent(); SetStyleFlags(); + Padding = new Padding(0, 0, 30, 2); edit.Font = UIFontColor.Font; edit.Left = 3; @@ -266,6 +267,16 @@ namespace Sunny.UI 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) { SizeChange(); @@ -273,15 +284,9 @@ namespace Sunny.UI 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.Left = 3; - edit.Width = Width - 30; + edit.Left = 3 + Padding.Left; + edit.Width = Width - Padding.Left - Padding.Right; } 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); } - Padding = new Padding(0, 0, 30, 2); g.FillRoundRectangle(GetFillColor(), new Rectangle(Width - 27, edit.Top, 25, edit.Height), Radius); Color color = GetRectColor(); SizeF sf = g.GetFontImageSize(dropSymbol, 24); diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index 19842ca3..dabd6bd3 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -44,8 +44,10 @@ namespace Sunny.UI SetStyleFlags(); CalcEditHeight(); Height = MinHeight; + iconSize = MinHeight; ShowText = false; Font = UIFontColor.Font; + Padding = new Padding(0, 0, 0, 0); edit.Top = (Height - edit.Height) / 2; edit.Left = 4; @@ -330,6 +332,12 @@ namespace Sunny.UI SizeChange(); } + protected override void OnPaddingChanged(EventArgs e) + { + base.OnPaddingChanged(e); + SizeChange(); + } + public void SetScrollInfo() { if (bar == null) @@ -370,8 +378,16 @@ namespace Sunny.UI if (Height > MaxHeight) Height = MaxHeight; edit.Top = (Height - edit.Height) / 2; - edit.Left = 4; - edit.Width = Width - 8; + if (icon == null) + { + 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 { @@ -807,5 +823,41 @@ namespace Sunny.UI { 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); + } + } } } \ No newline at end of file