* UIButton: 增加了AutoSize属性

This commit is contained in:
Sunny 2022-02-26 10:28:54 +08:00
parent ed17d205fe
commit b9edbe0524
7 changed files with 35 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -23,6 +23,7 @@
* 2020-09-14: V2.2.7 Tips颜色可设置
* 2021-07-18: V3.0.5 ShowFocusColorFocus状态
* 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();

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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