diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index 717b61e8..10a9a7ce 100644 Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 7e637a1d..c22a00e3 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI/Controls/UIButton.cs b/SunnyUI/Controls/UIButton.cs index 7e5d164e..afd05ce6 100644 --- a/SunnyUI/Controls/UIButton.cs +++ b/SunnyUI/Controls/UIButton.cs @@ -23,6 +23,7 @@ * 2020-09-14: V2.2.7 Tips颜色可设置 * 2021-07-18: V3.0.5 增加ShowFocusColor,用来显示Focus状态 * 2021-12-11: V3.0.9 增加了渐变色 + * 2022-02-26: V3.1.1 增加了AutoSize属性 ******************************************************************************/ using System; @@ -62,6 +63,20 @@ namespace Sunny.UI SetStyle(ControlStyles.StandardDoubleClick, UseDoubleClick); } + private bool autoSize; + + [Browsable(true), DefaultValue(false)] + [Description("自动大小"), Category("SunnyUI")] + public override bool AutoSize + { + get => autoSize; + set + { + autoSize = value; + Invalidate(); + } + } + private bool isClick; public void PerformClick() @@ -227,6 +242,13 @@ namespace Sunny.UI { base.OnPaint(e); + if (autoSize && Dock == DockStyle.None) + { + SizeF sf = e.Graphics.MeasureString(Text, Font); + if (Width != (int)(sf.Width) + 6) Width = (int)(sf.Width) + 6; + if (Height != (int)(sf.Height) + 6) Height = (int)(sf.Height) + 6; + } + if (Enabled && ShowTips && !string.IsNullOrEmpty(TipsText)) { e.Graphics.SetHighQuality(); diff --git a/SunnyUI/Controls/UICheckBox.cs b/SunnyUI/Controls/UICheckBox.cs index 47b89745..b2d9f7c1 100644 --- a/SunnyUI/Controls/UICheckBox.cs +++ b/SunnyUI/Controls/UICheckBox.cs @@ -49,7 +49,7 @@ namespace Sunny.UI protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - if (AutoSize) + if (AutoSize && Dock == DockStyle.None) { SizeF sf = Text.MeasureString(Font); int w = (int)sf.Width + ImageSize + 3; diff --git a/SunnyUI/Controls/UIMarkLabel.cs b/SunnyUI/Controls/UIMarkLabel.cs index 5faf80e3..fde504eb 100644 --- a/SunnyUI/Controls/UIMarkLabel.cs +++ b/SunnyUI/Controls/UIMarkLabel.cs @@ -119,7 +119,7 @@ namespace Sunny.UI base.OnPaint(e); SizeF TextSize = e.Graphics.MeasureString(Text, Font); - if (autoSize) + if (autoSize && Dock == DockStyle.None) { float width = (MarkPos == UIMarkPos.Left || MarkPos == UIMarkPos.Right) ? TextSize.Width + MarkSize + 2 : TextSize.Width; diff --git a/SunnyUI/Controls/UIRadioButton.cs b/SunnyUI/Controls/UIRadioButton.cs index 82987d01..4dc808ac 100644 --- a/SunnyUI/Controls/UIRadioButton.cs +++ b/SunnyUI/Controls/UIRadioButton.cs @@ -55,7 +55,7 @@ namespace Sunny.UI protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - if (AutoSize) + if (AutoSize && Dock == DockStyle.None) { SizeF sf = Text.MeasureString(Font); int w = (int)sf.Width + ImageSize + 3; diff --git a/SunnyUI/Controls/UISymbolButton.cs b/SunnyUI/Controls/UISymbolButton.cs index c24928b9..e893e613 100644 --- a/SunnyUI/Controls/UISymbolButton.cs +++ b/SunnyUI/Controls/UISymbolButton.cs @@ -42,6 +42,16 @@ namespace Sunny.UI ShowText = false; } + private bool autoSize; + + [Browsable(false)] + [Description("自动大小"), Category("SunnyUI")] + public override bool AutoSize + { + get => autoSize; + set => autoSize = false; + } + [DefaultValue(24)] [Description("字体图标大小"), Category("SunnyUI")] public int SymbolSize