diff --git a/SunnyUI/Controls/UISymbolButton.cs b/SunnyUI/Controls/UISymbolButton.cs
index 3a910a9f..852b5c59 100644
--- a/SunnyUI/Controls/UISymbolButton.cs
+++ b/SunnyUI/Controls/UISymbolButton.cs
@@ -71,6 +71,26 @@ namespace Sunny.UI
}
}
+ private int _symbolRotate = 0;
+
+ ///
+ /// å—ä½“å›¾æ ‡æ—‹è½¬è§’åº¦
+ ///
+ [DefaultValue(0)]
+ [Description("å—ä½“å›¾æ ‡æ—‹è½¬è§’åº¦"), Category("SunnyUI")]
+ public int SymbolRotate
+ {
+ get => _symbolRotate;
+ set
+ {
+ if (_symbolRotate != value)
+ {
+ _symbolRotate = value;
+ Invalidate();
+ }
+ }
+ }
+
private Color symbolColor = Color.White;
///
@@ -379,7 +399,7 @@ namespace Sunny.UI
{
if (Symbol > 0 && Image == null)
{
- e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(), ClientRectangle, SymbolOffset.X, SymbolOffset.Y);
+ e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(), ClientRectangle, SymbolOffset.X, SymbolOffset.Y, SymbolRotate);
}
if (Image != null)
@@ -396,7 +416,7 @@ namespace Sunny.UI
if (Symbol > 0 && Image == null)
{
e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(),
- new RectangleF((Width - allWidth) / 2.0f, 0, ImageSize.Width, Height), SymbolOffset.X, SymbolOffset.Y);
+ new RectangleF((Width - allWidth) / 2.0f, 0, ImageSize.Width, Height), SymbolOffset.X, SymbolOffset.Y, SymbolRotate);
}
if (Image != null)
@@ -466,7 +486,7 @@ namespace Sunny.UI
if (Symbol > 0 && Image == null)
{
e.Graphics.DrawFontImage(Symbol, SymbolSize, GetSymbolForeColor(),
- new Rectangle((int)left, (int)top, (int)ImageSize.Width, (int)ImageSize.Height), SymbolOffset.X, SymbolOffset.Y);
+ new Rectangle((int)left, (int)top, (int)ImageSize.Width, (int)ImageSize.Height), SymbolOffset.X, SymbolOffset.Y, SymbolRotate);
}
if (Image != null)
diff --git a/SunnyUI/Font/UFontImageHelper.cs b/SunnyUI/Font/UFontImageHelper.cs
index 8db19896..5141c663 100644
--- a/SunnyUI/Font/UFontImageHelper.cs
+++ b/SunnyUI/Font/UFontImageHelper.cs
@@ -109,43 +109,22 @@ namespace Sunny.UI
RectangleF rect, int xOffset = 0, int yOffSet = 0, int angle = 0)
{
SizeF sf = graphics.GetFontImageSize(symbol, symbolSize);
- graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(),
- rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx() + 1, xOffset, yOffSet);
- }
+ float left = rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx();
+ float top = rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx();
+ //graphics.DrawFontImage(symbol, symbolSize, color, left, top + 1, xOffset, yOffSet);
- public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color, int angle,
- RectangleF rect, int xOffset = 0, int yOffSet = 0)
- {
- SizeF sf = graphics.GetFontImageSize(symbol, symbolSize);
- using Bitmap bmp = new Bitmap(symbolSize, symbolSize);
- using Graphics g = Graphics.FromImage(bmp);
- g.DrawFontImage(symbol, symbolSize, color, (symbolSize - sf.Width) / 2.0f, (symbolSize - sf.Height) / 2.0f);
+ // °Ñ»°åµÄÔµã(ĬÈÏÊÇ×óÉϽÇ)¶¨Î»ÒƵ½ÎÄ×ÖÖÐÐÄ
+ graphics.TranslateTransform(left + sf.Width / 2, top + sf.Height / 2);
+ // Ðýת»°å
+ graphics.RotateTransform(angle);
+ // »ØÍË»°åx,yÖáÒÆ¶¯¹ýµÄ¾àÀë
+ graphics.TranslateTransform(-(left + sf.Width / 2), -(top + sf.Height / 2));
- using Bitmap bmp1 = RotateTransform(bmp, angle);
- graphics.DrawImage(angle == 0 ? bmp : bmp1,
- new RectangleF(rect.Left + (rect.Width - bmp1.Width) / 2.0f, rect.Top + (rect.Height - bmp1.Height) / 2.0f, bmp1.Width, bmp1.Height),
- new RectangleF(0, 0, bmp1.Width, bmp1.Height),
- GraphicsUnit.Pixel);
- }
+ graphics.DrawFontImage(symbol, symbolSize, color, left, top, xOffset, yOffSet);
- private static Bitmap RotateTransform(Bitmap originalImage, int angle)
- {
- // ´´½¨ÐµÄλͼ£¬´óСΪÐýתºóµÄͼƬ´óС
- Bitmap rotatedImage = new Bitmap(originalImage.Height, originalImage.Width);
-
- // ´´½¨»æÍ¼¶ÔÏó
- using Graphics g = Graphics.FromImage(rotatedImage);
-
- // ÉèÖûæÍ¼²ÎÊý£¬½«ÔʼͼƬÐýת90¡ã
- g.TranslateTransform(originalImage.Width / 2, originalImage.Height / 2);
- g.RotateTransform(angle);
-
- g.DrawImage(originalImage,
- new Rectangle(-originalImage.Width / 2, -originalImage.Height / 2, originalImage.Width, originalImage.Height),
- new Rectangle(0, 0, rotatedImage.Width, originalImage.Height),
- GraphicsUnit.Pixel);
- g.TranslateTransform(-originalImage.Width / 2, -originalImage.Height / 2);
- return rotatedImage;
+ graphics.TranslateTransform(left + sf.Width / 2, top + sf.Height / 2);
+ graphics.RotateTransform(-angle);
+ graphics.TranslateTransform(-(left + sf.Width / 2), -(top + sf.Height / 2));
}
///