为UIHeaderButton增加了TextImageRelation,实现文本和图像的相对位置设置
This commit is contained in:
parent
b1543067ae
commit
79ad5a28b1
@ -354,7 +354,19 @@ namespace Sunny.UI
|
||||
}
|
||||
}
|
||||
}
|
||||
public TextImageRelation textImageRelation = TextImageRelation.ImageAboveText;
|
||||
|
||||
[DefaultValue(typeof(TextImageRelation), "ImageAboveText")]
|
||||
[Description("指定图像与文本的相对位置"), Category("SunnyUI")]
|
||||
public TextImageRelation TextImageRelation
|
||||
{
|
||||
get => textImageRelation;
|
||||
set
|
||||
{
|
||||
textImageRelation = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
@ -416,38 +428,139 @@ namespace Sunny.UI
|
||||
{
|
||||
//重绘父类
|
||||
base.OnPaint(e);
|
||||
|
||||
SizeF ImageSize = new SizeF(0, 0);
|
||||
if (Symbol > 0)
|
||||
ImageSize = e.Graphics.GetFontImageSize(Symbol, SymbolSize);
|
||||
if (Image != null)
|
||||
ImageSize = Image.Size;
|
||||
|
||||
//字体图标
|
||||
if (Symbol > 0 && Image == null)
|
||||
{
|
||||
Color bcColor = CircleColor;
|
||||
if (ShowCircleHoverColor && IsHover)
|
||||
{
|
||||
bcColor = CircleHoverColor;
|
||||
}
|
||||
|
||||
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f, Padding.Top, CircleSize, CircleSize);
|
||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
||||
new RectangleF(
|
||||
symbolOffset.X + (Width - CircleSize) / 2.0f,
|
||||
symbolOffset.Y + Padding.Top,
|
||||
CircleSize,
|
||||
CircleSize));
|
||||
}
|
||||
else if (Image != null)
|
||||
{
|
||||
e.Graphics.DrawImage(Image, (Width - ImageSize.Width) / 2.0f, ImageTop, ImageSize.Width, ImageSize.Height);
|
||||
}
|
||||
|
||||
Color color = GetForeColor();
|
||||
SizeF sf = e.Graphics.MeasureString(Text, Font);
|
||||
e.Graphics.DrawString(Text, Font, color, (Width - sf.Width) / 2, Height - Padding.Bottom - sf.Height);
|
||||
|
||||
switch (textImageRelation)
|
||||
{
|
||||
/*case TextImageRelation.Overlay:
|
||||
{
|
||||
|
||||
}
|
||||
break; */
|
||||
case TextImageRelation.TextAboveImage:
|
||||
{
|
||||
#region 文本在上
|
||||
e.Graphics.DrawString(Text, Font, color, (Width - sf.Width) / 2, Padding.Top );
|
||||
|
||||
//字体图标
|
||||
if (Symbol > 0 && Image == null)
|
||||
{
|
||||
Color bcColor = CircleColor;
|
||||
if (ShowCircleHoverColor && IsHover)
|
||||
{
|
||||
bcColor = CircleHoverColor;
|
||||
}
|
||||
|
||||
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f, Height - Padding.Bottom- CircleSize, CircleSize, CircleSize);
|
||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
||||
new RectangleF(
|
||||
symbolOffset.X + (Width - CircleSize) / 2.0f,
|
||||
symbolOffset.Y + Height - Padding.Bottom - CircleSize,
|
||||
CircleSize,
|
||||
CircleSize));
|
||||
}
|
||||
else if (Image != null)
|
||||
{
|
||||
e.Graphics.DrawImage(Image, (Width - ImageSize.Width) / 2.0f, Height - Padding.Bottom - ImageSize.Height+imageTop, ImageSize.Width, ImageSize.Height);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
case TextImageRelation.ImageBeforeText:
|
||||
{
|
||||
#region 图片在前
|
||||
//字体图标
|
||||
if (Symbol > 0 && Image == null)
|
||||
{
|
||||
Color bcColor = CircleColor;
|
||||
if (ShowCircleHoverColor && IsHover)
|
||||
{
|
||||
bcColor = CircleHoverColor;
|
||||
}
|
||||
|
||||
e.Graphics.FillEllipse(bcColor, Padding.Left, (Height - CircleSize) / 2.0f, CircleSize, CircleSize);
|
||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
||||
new RectangleF(
|
||||
symbolOffset.X + Padding.Left,
|
||||
symbolOffset.Y + (Height - CircleSize) / 2.0f,
|
||||
CircleSize,
|
||||
CircleSize));
|
||||
}
|
||||
else if (Image != null)
|
||||
{
|
||||
e.Graphics.DrawImage(Image, ImageTop, (Height - ImageSize.Height) / 2.0f, ImageSize.Width, ImageSize.Height);
|
||||
}
|
||||
|
||||
e.Graphics.DrawString(Text, Font, color, Width - Padding.Right - sf.Width, (Height - sf.Height) / 2);
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
case TextImageRelation.TextBeforeImage :
|
||||
{
|
||||
#region 文本在前
|
||||
e.Graphics.DrawString(Text, Font, color, Padding.Left, (Height - sf.Height) / 2);
|
||||
|
||||
//字体图标
|
||||
if (Symbol > 0 && Image == null)
|
||||
{
|
||||
Color bcColor = CircleColor;
|
||||
if (ShowCircleHoverColor && IsHover)
|
||||
{
|
||||
bcColor = CircleHoverColor;
|
||||
}
|
||||
|
||||
e.Graphics.FillEllipse(bcColor, Width - Padding.Right - CircleSize, (Height - CircleSize) / 2.0f, CircleSize, CircleSize);
|
||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
||||
new RectangleF(
|
||||
symbolOffset.X + Width - Padding.Right - CircleSize,
|
||||
symbolOffset.Y + (Height - CircleSize) / 2.0f,
|
||||
CircleSize,
|
||||
CircleSize));
|
||||
}
|
||||
else if (Image != null)
|
||||
{
|
||||
e.Graphics.DrawImage(Image, Width - Padding.Right - ImageSize.Width + imageTop, (Height - ImageSize.Height) / 2.0f, ImageSize.Width, ImageSize.Height);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
default :
|
||||
{
|
||||
#region 图片在上
|
||||
//字体图标
|
||||
if (Symbol > 0 && Image == null)
|
||||
{
|
||||
Color bcColor = CircleColor;
|
||||
if (ShowCircleHoverColor && IsHover)
|
||||
{
|
||||
bcColor = CircleHoverColor;
|
||||
}
|
||||
|
||||
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f, Padding.Top, CircleSize, CircleSize);
|
||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
||||
new RectangleF(
|
||||
symbolOffset.X + (Width - CircleSize) / 2.0f,
|
||||
symbolOffset.Y + Padding.Top,
|
||||
CircleSize,
|
||||
CircleSize));
|
||||
}
|
||||
else if (Image != null)
|
||||
{
|
||||
e.Graphics.DrawImage(Image, (Width - ImageSize.Width) / 2.0f, ImageTop, ImageSize.Width, ImageSize.Height);
|
||||
}
|
||||
|
||||
e.Graphics.DrawString(Text, Font, color, (Width - sf.Width) / 2, Height - Padding.Bottom - sf.Height);
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user