* 重构DrawString函数
This commit is contained in:
parent
e045973d62
commit
39b482356d
@ -456,7 +456,7 @@ namespace Sunny.UI
|
|||||||
SizeF sf = g.MeasureString(data, TempFont);
|
SizeF sf = g.MeasureString(data, TempFont);
|
||||||
int angle = (Option.XAxis.AxisLabel.Angle + 36000) % 360;
|
int angle = (Option.XAxis.AxisLabel.Angle + 36000) % 360;
|
||||||
if (angle > 0 && angle <= 90)
|
if (angle > 0 && angle <= 90)
|
||||||
g.DrawString(data, TempFont, ForeColor, new PointF(start, DrawOrigin.Y + Option.XAxis.AxisTick.Length),
|
g.DrawRotateString(data, TempFont, ForeColor, new PointF(start, DrawOrigin.Y + Option.XAxis.AxisTick.Length),
|
||||||
new StringFormat() { Alignment = StringAlignment.Far }, (3600 - Option.XAxis.AxisLabel.Angle) % 360);
|
new StringFormat() { Alignment = StringAlignment.Far }, (3600 - Option.XAxis.AxisLabel.Angle) % 360);
|
||||||
else
|
else
|
||||||
g.DrawString(data, TempFont, ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length); start += DrawBarWidth;
|
g.DrawString(data, TempFont, ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length); start += DrawBarWidth;
|
||||||
@ -511,8 +511,7 @@ namespace Sunny.UI
|
|||||||
SizeF sfname = g.MeasureString(Option.YAxis.Name, TempFont);
|
SizeF sfname = g.MeasureString(Option.YAxis.Name, TempFont);
|
||||||
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
|
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
|
||||||
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
|
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
|
||||||
g.DrawString(Option.YAxis.Name, TempFont, ForeColor, new Point(x, y),
|
g.DrawRotateString(Option.YAxis.Name, TempFont, ForeColor, new Point(x, y), new StringFormat() { Alignment = StringAlignment.Center }, 270);
|
||||||
new StringFormat() { Alignment = StringAlignment.Center }, 270);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ namespace Sunny.UI
|
|||||||
SizeF sfName = g.MeasureString(Option.YAxis.Name, TempFont);
|
SizeF sfName = g.MeasureString(Option.YAxis.Name, TempFont);
|
||||||
float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f;
|
float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f;
|
||||||
float yy = Option.Grid.Top + DrawSize.Height / 2.0f;
|
float yy = Option.Grid.Top + DrawSize.Height / 2.0f;
|
||||||
g.DrawStringRotateAtCenter(Option.YAxis.Name, TempFont, ForeColor, new PointF(xx, yy), 270);
|
g.DrawRotateString(Option.YAxis.Name, TempFont, ForeColor, new PointF(xx, yy), 270);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Y2 Tick
|
//Y2 Tick
|
||||||
@ -458,7 +458,7 @@ namespace Sunny.UI
|
|||||||
SizeF sfName = g.MeasureString(Option.Y2Axis.Name, TempFont);
|
SizeF sfName = g.MeasureString(Option.Y2Axis.Name, TempFont);
|
||||||
float xx = Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length + widthMax + sfName.Height / 2.0f;
|
float xx = Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length + widthMax + sfName.Height / 2.0f;
|
||||||
float yy = Option.Grid.Top + DrawSize.Height / 2.0f;
|
float yy = Option.Grid.Top + DrawSize.Height / 2.0f;
|
||||||
g.DrawStringRotateAtCenter(Option.Y2Axis.Name, TempFont, ForeColor, new PointF(xx, yy), 90);
|
g.DrawRotateString(Option.Y2Axis.Name, TempFont, ForeColor, new PointF(xx, yy), 90);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,21 +49,6 @@ namespace Sunny.UI
|
|||||||
g.DrawString(text, font, br, rect, format);
|
g.DrawString(text, font, br, rect, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="rect">区域</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, RectangleF rect)
|
|
||||||
{
|
|
||||||
if (text.IsNullOrEmpty()) return;
|
|
||||||
using Brush br = color.Brush();
|
|
||||||
g.DrawString(text, font, br, rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 绘制字符串
|
/// 绘制字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -80,21 +65,6 @@ namespace Sunny.UI
|
|||||||
g.DrawString(text, font, br, rect, format);
|
g.DrawString(text, font, br, rect, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="rect">区域</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, Rectangle rect)
|
|
||||||
{
|
|
||||||
if (text.IsNullOrEmpty()) return;
|
|
||||||
using Brush br = color.Brush();
|
|
||||||
g.DrawString(text, font, br, rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 绘制字符串
|
/// 绘制字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -111,68 +81,6 @@ namespace Sunny.UI
|
|||||||
g.DrawString(text, font, br, x, y);
|
g.DrawString(text, font, br, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="pt">位置</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, Point pt)
|
|
||||||
=> g.DrawString(text, font, color, pt.X, pt.Y);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="pt">位置</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, PointF pt)
|
|
||||||
=> g.DrawString(text, font, color, pt.X, pt.Y);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="x">水平位置</param>
|
|
||||||
/// <param name="y">垂直位置</param>
|
|
||||||
/// <param name="format">格式</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, float x, float y, StringFormat format)
|
|
||||||
{
|
|
||||||
using Brush br = color.Brush();
|
|
||||||
g.DrawString(text, font, br, x, y, format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="pt">位置</param>
|
|
||||||
/// <param name="format">格式</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, PointF pt, StringFormat format)
|
|
||||||
=> g.DrawString(text, font, color, pt.X, pt.Y, format);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="pt">位置</param>
|
|
||||||
/// <param name="format">格式</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, Point pt, StringFormat format)
|
|
||||||
=> g.DrawString(text, font, color, pt.X, pt.Y, format);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 绘制字符串
|
/// 绘制字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -229,23 +137,6 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制字符串
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文字</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="color">颜色</param>
|
|
||||||
/// <param name="rect">区域</param>
|
|
||||||
/// <param name="format">格式</param>
|
|
||||||
/// <param name="angle">角度</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, RectangleF rect, StringFormat format, float angle)
|
|
||||||
{
|
|
||||||
if (text.IsNullOrEmpty()) return;
|
|
||||||
using Brush br = color.Brush();
|
|
||||||
g.DrawStringRotateAtCenter(text, font, color, rect.Center(), (int)angle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以文字中心点为原点,旋转文字
|
/// 以文字中心点为原点,旋转文字
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -255,11 +146,11 @@ namespace Sunny.UI
|
|||||||
/// <param name="color">颜色</param>
|
/// <param name="color">颜色</param>
|
||||||
/// <param name="centerPoint">文字中心点</param>
|
/// <param name="centerPoint">文字中心点</param>
|
||||||
/// <param name="angle">角度</param>
|
/// <param name="angle">角度</param>
|
||||||
public static void DrawStringRotateAtCenter(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle)
|
public static void DrawRotateString(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle)
|
||||||
{
|
{
|
||||||
if (text.IsNullOrEmpty()) return;
|
if (text.IsNullOrEmpty()) return;
|
||||||
using Brush br = color.Brush();
|
using Brush br = color.Brush();
|
||||||
g.DrawStringRotateAtCenter(text, font, br, centerPoint, angle);
|
g.DrawRotateString(text, font, br, centerPoint, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -271,7 +162,7 @@ namespace Sunny.UI
|
|||||||
/// <param name="brush">笔刷</param>
|
/// <param name="brush">笔刷</param>
|
||||||
/// <param name="centerPoint">文字中心点</param>
|
/// <param name="centerPoint">文字中心点</param>
|
||||||
/// <param name="angle">角度</param>
|
/// <param name="angle">角度</param>
|
||||||
public static void DrawStringRotateAtCenter(this Graphics g, string text, Font font, Brush brush, PointF centerPoint, float angle)
|
private static void DrawRotateString(this Graphics g, string text, Font font, Brush brush, PointF centerPoint, float angle)
|
||||||
{
|
{
|
||||||
if (text.IsNullOrEmpty()) return;
|
if (text.IsNullOrEmpty()) return;
|
||||||
SizeF sf = g.MeasureString(text, font);
|
SizeF sf = g.MeasureString(text, font);
|
||||||
@ -302,7 +193,7 @@ namespace Sunny.UI
|
|||||||
/// <param name="rotatePoint">旋转点</param>
|
/// <param name="rotatePoint">旋转点</param>
|
||||||
/// <param name="format">布局方式</param>
|
/// <param name="format">布局方式</param>
|
||||||
/// <param name="angle">角度</param>
|
/// <param name="angle">角度</param>
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Brush brush, PointF rotatePoint, StringFormat format, float angle)
|
private static void DrawRotateString(this Graphics g, string text, Font font, Brush brush, PointF rotatePoint, StringFormat format, float angle)
|
||||||
{
|
{
|
||||||
if (text.IsNullOrEmpty()) return;
|
if (text.IsNullOrEmpty()) return;
|
||||||
// Save the matrix
|
// Save the matrix
|
||||||
@ -326,27 +217,11 @@ namespace Sunny.UI
|
|||||||
/// <param name="rotatePoint">旋转点</param>
|
/// <param name="rotatePoint">旋转点</param>
|
||||||
/// <param name="format">格式</param>
|
/// <param name="format">格式</param>
|
||||||
/// <param name="angle">角度</param>
|
/// <param name="angle">角度</param>
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Color color, PointF rotatePoint, StringFormat format, float angle)
|
public static void DrawRotateString(this Graphics g, string text, Font font, Color color, PointF rotatePoint, StringFormat format, float angle)
|
||||||
{
|
{
|
||||||
if (text.IsNullOrEmpty()) return;
|
if (text.IsNullOrEmpty()) return;
|
||||||
using Brush br = color.Brush();
|
using Brush br = color.Brush();
|
||||||
g.DrawString(text, font, br, rotatePoint, format, angle);
|
g.DrawRotateString(text, font, br, rotatePoint, format, angle);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 绘制根据矩形旋转文本
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g">绘图图元</param>
|
|
||||||
/// <param name="text">文本</param>
|
|
||||||
/// <param name="font">字体</param>
|
|
||||||
/// <param name="brush">填充</param>
|
|
||||||
/// <param name="rect">局部矩形</param>
|
|
||||||
/// <param name="format">布局方式</param>
|
|
||||||
/// <param name="angle">角度</param>
|
|
||||||
public static void DrawString(this Graphics g, string text, Font font, Brush brush, RectangleF rect, StringFormat format, float angle)
|
|
||||||
{
|
|
||||||
if (text.IsNullOrEmpty()) return;
|
|
||||||
g.DrawStringRotateAtCenter(text, font, brush, rect.Center(), angle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -793,7 +793,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (ShowDescription && !string.IsNullOrEmpty(item.Description))
|
if (ShowDescription && !string.IsNullOrEmpty(item.Description))
|
||||||
{
|
{
|
||||||
g.DrawString(item.Description, e.Font, foreColor, new Point(ImageInterval, thumbnailSize + ImageInterval));
|
g.DrawString(item.Description, e.Font, foreColor, ImageInterval, thumbnailSize + ImageInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.Transform = oldTransform;
|
g.Transform = oldTransform;
|
||||||
|
@ -165,7 +165,7 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
if (TextAlign == ContentAlignment.MiddleCenter && Angle != 0 && !AutoSize)
|
if (TextAlign == ContentAlignment.MiddleCenter && Angle != 0 && !AutoSize)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawStringRotateAtCenter(Text, Font, ForeColor, this.ClientRectangle.Center(), Angle);
|
e.Graphics.DrawRotateString(Text, Font, ForeColor, this.ClientRectangle.Center(), Angle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user