* 重构DrawFontImage函数
This commit is contained in:
parent
f6f12c51c9
commit
a6c3de2ffb
@ -24,6 +24,7 @@
|
|||||||
* 2023-04-08: V3.3.4 DropDownList时,显示水印文字
|
* 2023-04-08: V3.3.4 DropDownList时,显示水印文字
|
||||||
* 2023-05-08: V3.3.6 最小高度限制,以防丢失边框
|
* 2023-05-08: V3.3.6 最小高度限制,以防丢失边框
|
||||||
* 2022-05-12: V3.3.6 重构DrawString函数
|
* 2022-05-12: V3.3.6 重构DrawString函数
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -410,17 +411,12 @@ namespace Sunny.UI
|
|||||||
int symbol = dropSymbol;
|
int symbol = dropSymbol;
|
||||||
if (NeedDrawClearButton)
|
if (NeedDrawClearButton)
|
||||||
{
|
{
|
||||||
symbol = 261527;
|
g.DrawFontImage(261527, 24, color, new Rectangle(Width - 28, 0, 28, Height), -1, 1);
|
||||||
SizeF sf = g.GetFontImageSize(symbol, 24);
|
|
||||||
g.DrawFontImage(symbol, 24, color, Width - 28 + (12 - sf.Width / 2.0f), (Height - sf.Height) / 2.0f, 1, 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SizeF sf = g.GetFontImageSize(symbol, 24);
|
g.DrawFontImage(symbol, 24, color, new Rectangle(Width - 28, 0, 28, Height), 1, 0);
|
||||||
g.DrawFontImage(symbol, 24, color, Width - 28 + (12 - sf.Width / 2.0f), (Height - sf.Height) / 2.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//g.DrawLine(RectColor, Width - 1, Radius / 2, Width - 1, Height - Radius);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool NeedDrawClearButton;
|
protected bool NeedDrawClearButton;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
* 2022-01-02: V3.0.9 增加角标
|
* 2022-01-02: V3.0.9 增加角标
|
||||||
* 2022-03-19: V3.1.1 重构主题配色
|
* 2022-03-19: V3.1.1 重构主题配色
|
||||||
* 2022-05-13: V3.3.6 重构DrawString函数
|
* 2022-05-13: V3.3.6 重构DrawString函数
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -612,9 +613,9 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
//重绘父类
|
//重绘父类
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
SizeF ImageSize = new SizeF(0, 0);
|
Size ImageSize = new Size(0, 0);
|
||||||
if (Symbol > 0)
|
if (Symbol > 0)
|
||||||
ImageSize = e.Graphics.GetFontImageSize(Symbol, SymbolSize);
|
ImageSize = new Size(SymbolSize, SymbolSize);
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
ImageSize = Image.Size;
|
ImageSize = Image.Size;
|
||||||
|
|
||||||
@ -636,13 +637,8 @@ namespace Sunny.UI
|
|||||||
bcColor = CircleHoverColor;
|
bcColor = CircleHoverColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f, Height - Padding.Bottom - CircleSize, CircleSize, CircleSize);
|
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f - 1, Height - Padding.Bottom - CircleSize - 1, CircleSize, CircleSize);
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(0, Height - Padding.Bottom - CircleSize, Width, CircleSize), symbolOffset.X, symbolOffset.Y);
|
||||||
new Rectangle(
|
|
||||||
symbolOffset.X + (int)(Width - CircleSize) / 2,
|
|
||||||
symbolOffset.Y + Height - Padding.Bottom - CircleSize,
|
|
||||||
CircleSize,
|
|
||||||
CircleSize));
|
|
||||||
}
|
}
|
||||||
else if (Image != null)
|
else if (Image != null)
|
||||||
{
|
{
|
||||||
@ -664,13 +660,8 @@ namespace Sunny.UI
|
|||||||
bcColor = CircleHoverColor;
|
bcColor = CircleHoverColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Graphics.FillEllipse(bcColor, Padding.Left, (Height - CircleSize) / 2.0f, CircleSize, CircleSize);
|
e.Graphics.FillEllipse(bcColor, Padding.Left - 1, (Height - CircleSize) / 2.0f - 1, CircleSize, CircleSize);
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(Padding.Left, 0, CircleSize, Height), symbolOffset.X, symbolOffset.Y);
|
||||||
new Rectangle(
|
|
||||||
symbolOffset.X + Padding.Left,
|
|
||||||
symbolOffset.Y + (int)(Height - CircleSize) / 2,
|
|
||||||
CircleSize,
|
|
||||||
CircleSize));
|
|
||||||
}
|
}
|
||||||
else if (Image != null)
|
else if (Image != null)
|
||||||
{
|
{
|
||||||
@ -696,13 +687,8 @@ namespace Sunny.UI
|
|||||||
bcColor = CircleHoverColor;
|
bcColor = CircleHoverColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Graphics.FillEllipse(bcColor, Width - Padding.Right - CircleSize, (Height - CircleSize) / 2.0f, CircleSize, CircleSize);
|
e.Graphics.FillEllipse(bcColor, Width - Padding.Right - CircleSize - 1, (Height - CircleSize) / 2.0f - 1, CircleSize, CircleSize);
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(Width - Padding.Right - CircleSize, 0, CircleSize, Height), symbolOffset.X, symbolOffset.Y);
|
||||||
new Rectangle(
|
|
||||||
symbolOffset.X + Width - Padding.Right - CircleSize,
|
|
||||||
symbolOffset.Y + (int)(Height - CircleSize) / 2,
|
|
||||||
CircleSize,
|
|
||||||
CircleSize));
|
|
||||||
}
|
}
|
||||||
else if (Image != null)
|
else if (Image != null)
|
||||||
{
|
{
|
||||||
@ -724,13 +710,8 @@ namespace Sunny.UI
|
|||||||
bcColor = CircleHoverColor;
|
bcColor = CircleHoverColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f, Padding.Top, CircleSize, CircleSize);
|
e.Graphics.FillEllipse(bcColor, (Width - CircleSize) / 2.0f - 1, Padding.Top - 1, CircleSize, CircleSize);
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor,
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(0, Padding.Top, Width, CircleSize), symbolOffset.X, symbolOffset.Y);
|
||||||
new Rectangle(
|
|
||||||
symbolOffset.X + (int)(Width - CircleSize) / 2,
|
|
||||||
symbolOffset.Y + Padding.Top,
|
|
||||||
CircleSize,
|
|
||||||
CircleSize));
|
|
||||||
}
|
}
|
||||||
else if (Image != null)
|
else if (Image != null)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
* 2022-07-28: V3.2.2 删除界面此控件的编辑器
|
* 2022-07-28: V3.2.2 删除界面此控件的编辑器
|
||||||
* 2023-02-22: V3.3.2 去除下拉菜单宽度调整
|
* 2023-02-22: V3.3.2 去除下拉菜单宽度调整
|
||||||
* 2022-05-12: V3.3.6 重构DrawString函数
|
* 2022-05-12: V3.3.6 重构DrawString函数
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -536,14 +537,13 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (ShowItemsArrow && node.Nodes.Count > 0)
|
if (ShowItemsArrow && node.Nodes.Count > 0)
|
||||||
{
|
{
|
||||||
SizeF imageSize = e.Graphics.GetFontImageSize(61703, 24);
|
|
||||||
if (i != SelectedIndex)
|
if (i != SelectedIndex)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawFontImage(61703, 24, textColor, NodeX + i * NodeSize.Width + rect.Width - 24, rect.Top + (rect.Height - imageSize.Height) / 2);
|
e.Graphics.DrawFontImage(61703, 24, textColor, new Rectangle(NodeX + i * NodeSize.Width + rect.Width - 24, rect.Top, 24, rect.Height));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e.Graphics.DrawFontImage(NavBarMenu.Visible ? 61702 : 61703, 24, textColor, NodeX + i * NodeSize.Width + rect.Width - 24, rect.Top + (rect.Height - imageSize.Height) / 2);
|
e.Graphics.DrawFontImage(NavBarMenu.Visible ? 61702 : 61703, 24, textColor, new Rectangle(NodeX + i * NodeSize.Width + rect.Width - 24, rect.Top, 24, rect.Height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
* 2023-02-02: V3.3.1 修复了鼠标离开事件
|
* 2023-02-02: V3.3.1 修复了鼠标离开事件
|
||||||
* 2023-02-10: V3.3.2 有子节点时,鼠标左键点击父级点展开/收缩,右键选中
|
* 2023-02-10: V3.3.2 有子节点时,鼠标左键点击父级点展开/收缩,右键选中
|
||||||
* 2022-05-12: V3.3.6 重构DrawString函数
|
* 2022-05-12: V3.3.6 重构DrawString函数
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -730,10 +731,9 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
if (MenuHelper.GetSymbol(e.Node) > 0)
|
if (MenuHelper.GetSymbol(e.Node) > 0)
|
||||||
{
|
{
|
||||||
SizeF fiSize = e.Graphics.GetFontImageSize(MenuHelper.GetSymbol(e.Node), MenuHelper.GetSymbolSize(e.Node));
|
|
||||||
Color color = e.Node == SelectedNode ? SelectedForeColor : ForeColor;
|
Color color = e.Node == SelectedNode ? SelectedForeColor : ForeColor;
|
||||||
Point offset = MenuHelper.GetSymbolOffset(e.Node);
|
Point offset = MenuHelper.GetSymbolOffset(e.Node);
|
||||||
e.Graphics.DrawFontImage(MenuHelper.GetSymbol(e.Node), MenuHelper.GetSymbolSize(e.Node), color, imageLeft + (MenuHelper.GetSymbolSize(e.Node) - fiSize.Width) / 2.0f + offset.X, e.Bounds.Y + (e.Bounds.Height - fiSize.Height) / 2 + offset.Y);
|
e.Graphics.DrawFontImage(MenuHelper.GetSymbol(e.Node), MenuHelper.GetSymbolSize(e.Node), color, new Rectangle(imageLeft, e.Bounds.Y, MenuHelper.GetSymbolSize(e.Node), e.Bounds.Height), offset.X, offset.Y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
* 2022-01-05: V3.0.9 字体图标增加颜色设置
|
* 2022-01-05: V3.0.9 字体图标增加颜色设置
|
||||||
* 2022-03-19: V3.1.1 重构主题配色
|
* 2022-03-19: V3.1.1 重构主题配色
|
||||||
* 2022-05-15: V3.3.6 重构DrawString函数
|
* 2022-05-15: V3.3.6 重构DrawString函数
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -37,7 +38,7 @@ namespace Sunny.UI
|
|||||||
public class UISymbolButton : UIButton, ISymbol
|
public class UISymbolButton : UIButton, ISymbol
|
||||||
{
|
{
|
||||||
private int _symbolSize = 24;
|
private int _symbolSize = 24;
|
||||||
private int _imageInterval = 2;
|
private int _imageInterval = 0;
|
||||||
|
|
||||||
public UISymbolButton()
|
public UISymbolButton()
|
||||||
{
|
{
|
||||||
@ -200,7 +201,7 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[DefaultValue(2)]
|
[DefaultValue(0)]
|
||||||
[Description("图片文字间间隔"), Category("SunnyUI")]
|
[Description("图片文字间间隔"), Category("SunnyUI")]
|
||||||
public int ImageInterval
|
public int ImageInterval
|
||||||
{
|
{
|
||||||
@ -279,7 +280,7 @@ namespace Sunny.UI
|
|||||||
if (IsCircle)
|
if (IsCircle)
|
||||||
{
|
{
|
||||||
int size = Math.Min(Width, Height) - 2 - CircleRectWidth;
|
int size = Math.Min(Width, Height) - 2 - CircleRectWidth;
|
||||||
g.FillEllipse(GetFillColor(), (Width - size) / 2.0f, (Height - size) / 2.0f, size, size);
|
g.FillEllipse(GetFillColor(), (Width - size) / 2.0f - 1, (Height - size) / 2.0f - 1, size, size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -313,7 +314,7 @@ namespace Sunny.UI
|
|||||||
int size = Math.Min(Width, Height) - 2 - CircleRectWidth;
|
int size = Math.Min(Width, Height) - 2 - CircleRectWidth;
|
||||||
using var pn = new Pen(GetRectColor(), CircleRectWidth);
|
using var pn = new Pen(GetRectColor(), CircleRectWidth);
|
||||||
g.SetHighQuality();
|
g.SetHighQuality();
|
||||||
g.DrawEllipse(pn, (Width - size) / 2.0f, (Height - size) / 2.0f, size, size);
|
g.DrawEllipse(pn, (Width - size) / 2.0f - 1, (Height - size) / 2.0f - 1, size, size);
|
||||||
g.SetDefaultQuality();
|
g.SetDefaultQuality();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -356,9 +357,9 @@ namespace Sunny.UI
|
|||||||
//重绘父类
|
//重绘父类
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
|
|
||||||
SizeF ImageSize = new SizeF(0, 0);
|
Size ImageSize = new Size(0, 0);
|
||||||
if (Symbol > 0)
|
if (Symbol > 0)
|
||||||
ImageSize = e.Graphics.GetFontImageSize(Symbol, SymbolSize);
|
ImageSize = new Size(SymbolSize, SymbolSize);
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
ImageSize = Image.Size;
|
ImageSize = Image.Size;
|
||||||
|
|
||||||
@ -368,7 +369,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (ImageAlign == ContentAlignment.MiddleCenter && TextAlign == ContentAlignment.MiddleCenter)
|
if (ImageAlign == ContentAlignment.MiddleCenter && TextAlign == ContentAlignment.MiddleCenter)
|
||||||
{
|
{
|
||||||
if (ImageSize.Width.Equals(0))
|
if (ImageSize.Width == 0)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawString(Text, Font, color, ClientRectangle, ContentAlignment.MiddleCenter);
|
e.Graphics.DrawString(Text, Font, color, ClientRectangle, ContentAlignment.MiddleCenter);
|
||||||
}
|
}
|
||||||
@ -378,30 +379,24 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
if (Symbol > 0 && Image == null)
|
if (Symbol > 0 && Image == null)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(),
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(), ClientRectangle, SymbolOffset.X, SymbolOffset.Y);
|
||||||
new Rectangle(
|
|
||||||
(int)(Width - ImageSize.Width) / 2,
|
|
||||||
Padding.Top + (int)(Height - ImageSize.Height - Padding.Top - Padding.Bottom) / 2,
|
|
||||||
(int)ImageSize.Width, (int)ImageSize.Height), SymbolOffset.X, SymbolOffset.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawImage(Image,
|
e.Graphics.DrawImage(Image, (Width - ImageSize.Width) / 2.0f,
|
||||||
(Width - ImageSize.Width) / 2.0f,
|
Padding.Top + (Height - ImageSize.Height - Padding.Top - Padding.Bottom) / 2.0f, ImageSize.Width, ImageSize.Height);
|
||||||
Padding.Top + (Height - ImageSize.Height - Padding.Top - Padding.Bottom) / 2.0f,
|
|
||||||
ImageSize.Width, ImageSize.Height);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float allWidth = ImageSize.Width + ImageInterval + TextSize.Width;
|
int allWidth = ImageSize.Width + ImageInterval + TextSize.Width;
|
||||||
|
|
||||||
if (Symbol > 0 && Image == null)
|
if (Symbol > 0 && Image == null)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(),
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(),
|
||||||
new Rectangle((int)(Width - allWidth) / 2, (int)(Height - ImageSize.Height) / 2, (int)ImageSize.Width, (int)ImageSize.Height), SymbolOffset.X, SymbolOffset.Y);
|
new RectangleF((Width - allWidth) / 2.0f, 0, ImageSize.Width, Height), SymbolOffset.X, SymbolOffset.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
@ -410,7 +405,7 @@ namespace Sunny.UI
|
|||||||
ImageSize.Width, ImageSize.Height);
|
ImageSize.Width, ImageSize.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Graphics.DrawString(Text, Font, color, new Rectangle((int)((Width - allWidth) / 2 + ImageSize.Width + ImageInterval), 0, Width, Height), ContentAlignment.MiddleLeft);
|
e.Graphics.DrawString(Text, Font, color, new Rectangle((int)((Width - allWidth) / 2.0f + ImageSize.Width + ImageInterval), 0, Width, Height), ContentAlignment.MiddleLeft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* 2021-12-24: V3.0.9 修复Dock和AutoSize同时设置的Bug
|
* 2021-12-24: V3.0.9 修复Dock和AutoSize同时设置的Bug
|
||||||
* 2022-03-19: V3.1.1 重构主题配色
|
* 2022-03-19: V3.1.1 重构主题配色
|
||||||
* 2022-05-12: V3.3.6 重构DrawString函数
|
* 2022-05-12: V3.3.6 重构DrawString函数
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -37,7 +38,7 @@ namespace Sunny.UI
|
|||||||
public sealed class UISymbolLabel : UIControl, ISymbol
|
public sealed class UISymbolLabel : UIControl, ISymbol
|
||||||
{
|
{
|
||||||
private int _symbolSize = 24;
|
private int _symbolSize = 24;
|
||||||
private int _imageInterval = 2;
|
private int _imageInterval = 0;
|
||||||
|
|
||||||
private Color symbolColor;
|
private Color symbolColor;
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[DefaultValue(2)]
|
[DefaultValue(0)]
|
||||||
[Description("图标和文字间间隔"), Category("SunnyUI")]
|
[Description("图标和文字间间隔"), Category("SunnyUI")]
|
||||||
public int ImageInterval
|
public int ImageInterval
|
||||||
{
|
{
|
||||||
@ -240,58 +241,59 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
//重绘父类
|
//重绘父类
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
|
|
||||||
float left = 0;
|
|
||||||
float top = 0;
|
|
||||||
SizeF ImageSize = e.Graphics.GetFontImageSize(Symbol, SymbolSize);
|
|
||||||
Size TextSize = TextRenderer.MeasureText(Text, Font);
|
Size TextSize = TextRenderer.MeasureText(Text, Font);
|
||||||
|
|
||||||
|
int height = Math.Max(SymbolSize, TextSize.Height);
|
||||||
|
int width = SymbolSize + ImageInterval + TextSize.Width;
|
||||||
|
|
||||||
if (Dock == DockStyle.None && autoSize)
|
if (Dock == DockStyle.None && autoSize)
|
||||||
{
|
{
|
||||||
int width = (int)(SymbolSize + ImageInterval * 3 + TextSize.Width);
|
TextAlign = ContentAlignment.MiddleCenter;
|
||||||
int height = (int)Math.Max(SymbolSize, TextSize.Height);
|
if (Width != width + 4) Width = width + 4;
|
||||||
if (Width != width) Width = width;
|
if (Height != height + 4) Height = height + 4;
|
||||||
if (Height != height) Height = height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextAlign == ContentAlignment.TopCenter || TextAlign == ContentAlignment.TopLeft || TextAlign == ContentAlignment.TopRight)
|
Rectangle rect;
|
||||||
|
switch (TextAlign)
|
||||||
{
|
{
|
||||||
top = Padding.Top;
|
case ContentAlignment.TopLeft:
|
||||||
}
|
rect = new Rectangle(Padding.Left, Padding.Top, width, height);
|
||||||
|
break;
|
||||||
if (TextAlign == ContentAlignment.MiddleCenter || TextAlign == ContentAlignment.MiddleLeft || TextAlign == ContentAlignment.MiddleRight)
|
case ContentAlignment.TopCenter:
|
||||||
{
|
rect = new Rectangle((Width - width) / 2, Padding.Top, width, height);
|
||||||
top = Padding.Top + (Height - Padding.Top - Padding.Bottom - ImageSize.Height) / 2.0f;
|
break;
|
||||||
}
|
case ContentAlignment.TopRight:
|
||||||
|
rect = new Rectangle(Width - width - Padding.Right, Padding.Top, width, height);
|
||||||
if (TextAlign == ContentAlignment.BottomCenter || TextAlign == ContentAlignment.BottomLeft || TextAlign == ContentAlignment.BottomRight)
|
break;
|
||||||
{
|
case ContentAlignment.MiddleLeft:
|
||||||
top = Height - Padding.Bottom - ImageSize.Height;
|
rect = new Rectangle(Padding.Left, (Height - height) / 2, width, height);
|
||||||
}
|
break;
|
||||||
|
case ContentAlignment.MiddleCenter:
|
||||||
if (TextAlign == ContentAlignment.TopCenter || TextAlign == ContentAlignment.MiddleCenter || TextAlign == ContentAlignment.BottomCenter)
|
rect = new Rectangle((Width - width) / 2, (Height - height) / 2, width, height);
|
||||||
{
|
break;
|
||||||
left = Padding.Left + (Width - TextSize.Width - Padding.Left - Padding.Right) / 2.0f;
|
case ContentAlignment.MiddleRight:
|
||||||
left = left - ImageInterval - ImageSize.Width;
|
rect = new Rectangle(Width - width - Padding.Right, (Height - height) / 2, width, height);
|
||||||
}
|
break;
|
||||||
|
case ContentAlignment.BottomLeft:
|
||||||
if (TextAlign == ContentAlignment.TopLeft || TextAlign == ContentAlignment.MiddleLeft || TextAlign == ContentAlignment.BottomLeft)
|
rect = new Rectangle(Padding.Left, Height - Padding.Bottom - height, width, height);
|
||||||
{
|
break;
|
||||||
left = ImageInterval;
|
case ContentAlignment.BottomCenter:
|
||||||
}
|
rect = new Rectangle((Width - width) / 2, Height - Padding.Bottom - height, width, height);
|
||||||
|
break;
|
||||||
if (TextAlign == ContentAlignment.TopRight || TextAlign == ContentAlignment.MiddleRight || TextAlign == ContentAlignment.BottomRight)
|
case ContentAlignment.BottomRight:
|
||||||
{
|
rect = new Rectangle(Width - width - Padding.Right, Height - Padding.Bottom - height, width, height);
|
||||||
left = Width - Padding.Right - TextSize.Width - ImageInterval - ImageSize.Width;
|
break;
|
||||||
|
default:
|
||||||
|
rect = new Rectangle((Width - width) / 2, (Height - height) / 2, width, height);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Text.IsNullOrEmpty())
|
if (Text.IsNullOrEmpty())
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, symbolColor, ImageInterval + (Width - ImageSize.Width) / 2.0f, (Height - ImageSize.Height) / 2.0f, SymbolOffset.X, SymbolOffset.Y);
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, symbolColor, (Width - SymbolSize) / 2.0f, (Height - SymbolSize) / 2.0f, SymbolOffset.X, SymbolOffset.Y);
|
||||||
else
|
else
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, symbolColor, left, top, SymbolOffset.X, SymbolOffset.Y);
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, symbolColor, new Rectangle(rect.Left, rect.Top, SymbolSize, rect.Height), SymbolOffset.X, SymbolOffset.Y);
|
||||||
|
|
||||||
Rectangle rect = new Rectangle((int)left + SymbolSize, (int)top, Width, SymbolSize);
|
e.Graphics.DrawString(Text, Font, ForeColor, rect, ContentAlignment.MiddleRight);
|
||||||
e.Graphics.DrawString(Text, Font, ForeColor, rect, ContentAlignment.MiddleLeft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPaintFore(Graphics g, GraphicsPath path)
|
protected override void OnPaintFore(Graphics g, GraphicsPath path)
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
* 感谢:麦壳饼 https://gitee.com/maikebing
|
* 感谢:麦壳饼 https://gitee.com/maikebing
|
||||||
* 2021-06-15: V3.0.4 增加FontAwesomeV5的字体图标,重构代码
|
* 2021-06-15: V3.0.4 增加FontAwesomeV5的字体图标,重构代码
|
||||||
* 2021-06-15: V3.3.5 增加FontAwesomeV6的字体图标,重构代码
|
* 2021-06-15: V3.3.5 增加FontAwesomeV6的字体图标,重构代码
|
||||||
|
* 2022-05-16: V3.3.6 重构DrawFontImage函数
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -106,7 +107,7 @@ namespace Sunny.UI
|
|||||||
/// <param name="symbol">字符</param>
|
/// <param name="symbol">字符</param>
|
||||||
/// <param name="symbolSize">大小</param>
|
/// <param name="symbolSize">大小</param>
|
||||||
/// <returns>字体大小</returns>
|
/// <returns>字体大小</returns>
|
||||||
public static SizeF GetFontImageSize(this Graphics graphics, int symbol, int symbolSize)
|
private static SizeF GetFontImageSize(this Graphics graphics, int symbol, int symbolSize)
|
||||||
{
|
{
|
||||||
Font font = GetFont(symbol, symbolSize);
|
Font font = GetFont(symbol, symbolSize);
|
||||||
if (font == null)
|
if (font == null)
|
||||||
@ -161,10 +162,7 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
//字体
|
//字体
|
||||||
Font font = GetFont(symbol, symbolSize);
|
Font font = GetFont(symbol, symbolSize);
|
||||||
if (font == null)
|
if (font == null) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var symbolValue = GetSymbolValue(symbol);
|
var symbolValue = GetSymbolValue(symbol);
|
||||||
string text = char.ConvertFromUtf32(symbolValue);
|
string text = char.ConvertFromUtf32(symbolValue);
|
||||||
@ -308,12 +306,7 @@ namespace Sunny.UI
|
|||||||
public Font GetFont(int iconText, int imageSize)
|
public Font GetFont(int iconText, int imageSize)
|
||||||
{
|
{
|
||||||
int item = GetFontSize(iconText, imageSize);
|
int item = GetFontSize(iconText, imageSize);
|
||||||
if (Fonts.ContainsKey(item))
|
return Fonts.ContainsKey(item) ? Fonts[item] : null;
|
||||||
{
|
|
||||||
return Fonts[GetFontSize(iconText, imageSize)];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -324,11 +317,7 @@ namespace Sunny.UI
|
|||||||
/// <returns>字体大小</returns>
|
/// <returns>字体大小</returns>
|
||||||
public int GetFontSize(int symbol, int imageSize)
|
public int GetFontSize(int symbol, int imageSize)
|
||||||
{
|
{
|
||||||
using (Bitmap bitmap = new Bitmap(48, 48))
|
return BinarySearch(GDI.Graphics(), MinFontSize, MaxFontSize, symbol, imageSize);
|
||||||
using (Graphics graphics = Graphics.FromImage(bitmap))
|
|
||||||
{
|
|
||||||
return BinarySearch(graphics, MinFontSize, MaxFontSize, symbol, imageSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int BinarySearch(Graphics graphics, int low, int high, int symbol, int imageSize)
|
public int BinarySearch(Graphics graphics, int low, int high, int symbol, int imageSize)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user