* 重构DrawString函数
This commit is contained in:
parent
decb112c21
commit
cf5727b374
@ -18,6 +18,7 @@
|
||||
*
|
||||
* 2020-06-06: V2.2.5 增加文件说明
|
||||
* 2020-09-10: V2.2.7 增加图表的边框线颜色设置
|
||||
* 2022-05-14: V3.3.6 重构DrawString函数
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -267,40 +268,10 @@ namespace Sunny.UI
|
||||
protected void DrawTitle(Graphics g, UITitle title)
|
||||
{
|
||||
if (title == null) return;
|
||||
SizeF sf = g.MeasureString(title.Text, Font);
|
||||
float left = 0;
|
||||
switch (title.Left)
|
||||
{
|
||||
case UILeftAlignment.Left: left = TextInterval; break;
|
||||
case UILeftAlignment.Center: left = (Width - sf.Width) / 2.0f; break;
|
||||
case UILeftAlignment.Right: left = Width - TextInterval - sf.Width; break;
|
||||
}
|
||||
|
||||
float top = 0;
|
||||
switch (title.Top)
|
||||
{
|
||||
case UITopAlignment.Top: top = TextInterval; break;
|
||||
case UITopAlignment.Center: top = (Height - sf.Height) / 2.0f; break;
|
||||
case UITopAlignment.Bottom: top = Height - TextInterval - sf.Height; break;
|
||||
}
|
||||
|
||||
g.DrawString(title.Text, Font, ChartStyle.ForeColor, left, top);
|
||||
|
||||
SizeF sfs = g.MeasureString(title.SubText, TempFont);
|
||||
switch (title.Left)
|
||||
{
|
||||
case UILeftAlignment.Left: left = TextInterval; break;
|
||||
case UILeftAlignment.Center: left = (Width - sfs.Width) / 2.0f; break;
|
||||
case UILeftAlignment.Right: left = Width - TextInterval - sf.Width; break;
|
||||
}
|
||||
switch (title.Top)
|
||||
{
|
||||
case UITopAlignment.Top: top = top + sf.Height; break;
|
||||
case UITopAlignment.Center: top = top + sf.Height; break;
|
||||
case UITopAlignment.Bottom: top = top - sf.Height; break;
|
||||
}
|
||||
|
||||
g.DrawString(title.SubText, TempFont, ChartStyle.ForeColor, left, top);
|
||||
Size sf = TextRenderer.MeasureText(title.Text, Font);
|
||||
g.DrawString(title.Text, Font, ChartStyle.ForeColor, new Rectangle(TextInterval, TextInterval, Width - TextInterval * 2, Height - TextInterval * 2), (StringAlignment)((int)title.Left), (StringAlignment)((int)title.Top));
|
||||
g.DrawString(title.SubText, TempFont, ChartStyle.ForeColor, new Rectangle(TextInterval, TextInterval, Width - TextInterval * 2, Height - TextInterval * 2),
|
||||
(StringAlignment)((int)title.Left), (StringAlignment)((int)title.Top), 0, title.Top == UITopAlignment.Bottom ? -sf.Height : sf.Height);
|
||||
}
|
||||
|
||||
protected void DrawLegend(Graphics g, UILegend legend)
|
||||
@ -362,7 +333,7 @@ namespace Sunny.UI
|
||||
if (legend.Orient == UIOrient.Horizontal)
|
||||
{
|
||||
g.FillRoundRectangle(color, (int)startLeft, (int)top + 1, 18, (int)oneHeight - 2, 5);
|
||||
g.DrawString(data, TempLegendFont, color, startLeft + 20, top);
|
||||
g.DrawString(data, TempLegendFont, color, new Rectangle((int)startLeft + 18, (int)top, Width, Height), ContentAlignment.TopLeft);
|
||||
startLeft += 22;
|
||||
startLeft += sf.Width;
|
||||
}
|
||||
@ -370,7 +341,7 @@ namespace Sunny.UI
|
||||
if (legend.Orient == UIOrient.Vertical)
|
||||
{
|
||||
g.FillRoundRectangle(color, (int)left, (int)startTop + 1, 18, (int)oneHeight - 2, 5);
|
||||
g.DrawString(data, TempLegendFont, color, left + 20, startTop);
|
||||
g.DrawString(data, TempLegendFont, color, new Rectangle((int)left + 18, (int)startTop, Width, Height), ContentAlignment.TopLeft);
|
||||
startTop += oneHeight;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
* 2020-06-06: V2.2.5 增加文件说明
|
||||
* 2021-07-22: V3.0.5 增加更新数据的方法
|
||||
* 2022-07-29: V3.2.2 数据显示的小数位数重构调整至Option.DecimalPlaces
|
||||
* 2022-05-14: V3.3.6 重构DrawString函数
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -180,8 +181,7 @@ namespace Sunny.UI
|
||||
{
|
||||
if (pie.Label.Position == UIPieSeriesLabelPosition.Center)
|
||||
{
|
||||
SizeF sf = g.MeasureString(pie.Data[azIndex].Name, Font);
|
||||
g.DrawString(pie.Data[azIndex].Name, Font, color, angle.Center.X - sf.Width / 2.0f, angle.Center.Y - sf.Height / 2.0f);
|
||||
g.DrawString(pie.Data[azIndex].Name, Font, color, new Rectangle((int)angle.Center.X - Width, (int)angle.Center.Y - Height, Width * 2, Height * 2), ContentAlignment.MiddleCenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
* 2020-06-06: V2.2.5 增加文件说明
|
||||
* 2021-07-22: V3.0.5 增加更新数据的方法
|
||||
* 2022-07-29: V3.2.2 数据显示的小数位数重构调整至Option.DecimalPlaces
|
||||
* 2022-05-14: V3.3.6 重构DrawString函数
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -193,20 +194,32 @@ namespace Sunny.UI
|
||||
if (pie.Data[azIndex].Value > 0)
|
||||
{
|
||||
string text = name + pie.Data[azIndex].Value.ToString("F" + Option.DecimalPlaces);
|
||||
SizeF sf = g.MeasureString(text, TempFont);
|
||||
PointF pf;
|
||||
Size sf = TextRenderer.MeasureText(text, TempFont);
|
||||
int added = 9;
|
||||
float left = 0, top = 0;
|
||||
if (az >= 0 && az < 90)
|
||||
pf = new PointF((float)(DrawCenter(pie).X + RadiusSize(pie) * x + added), (float)(DrawCenter(pie).Y - RadiusSize(pie) * y - sf.Height - added));
|
||||
{
|
||||
left = (float)(DrawCenter(pie).X + RadiusSize(pie) * x + added);
|
||||
top = (float)(DrawCenter(pie).Y - RadiusSize(pie) * y - sf.Height - added);
|
||||
}
|
||||
else if (az >= 90 && az < 180)
|
||||
pf = new PointF((float)(DrawCenter(pie).X + RadiusSize(pie) * x + added), (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + added));
|
||||
{
|
||||
left = (float)(DrawCenter(pie).X + RadiusSize(pie) * x + added);
|
||||
top = (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + added);
|
||||
}
|
||||
else if (az >= 180 && az < 270)
|
||||
pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + added));
|
||||
{
|
||||
left = (float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width;
|
||||
top = (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + added);
|
||||
}
|
||||
else
|
||||
pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - added);
|
||||
{
|
||||
left = (float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width;
|
||||
top = (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - added;
|
||||
}
|
||||
|
||||
if (pie.Data[azIndex].Value > 0)
|
||||
g.DrawString(text, TempFont, color, pf.X, pf.Y);
|
||||
g.DrawString(text, TempFont, color, new Rectangle((int)left, (int)top, Width, Height), ContentAlignment.TopLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,18 +191,7 @@ namespace Sunny.UI
|
||||
set
|
||||
{
|
||||
showType = value;
|
||||
switch (value)
|
||||
{
|
||||
case UIDateType.YearMonthDay:
|
||||
DateFormat = "yyyy-MM-dd";
|
||||
break;
|
||||
case UIDateType.YearMonth:
|
||||
DateFormat = "yyyy-MM";
|
||||
break;
|
||||
case UIDateType.Year:
|
||||
DateFormat = "yyyy";
|
||||
break;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +273,19 @@ namespace Sunny.UI
|
||||
{
|
||||
if (value < new DateTime(1900, 1, 1))
|
||||
value = new DateTime(1900, 1, 1);
|
||||
|
||||
switch (ShowType)
|
||||
{
|
||||
case UIDateType.YearMonthDay:
|
||||
Text = value.ToString(dateFormat);
|
||||
break;
|
||||
case UIDateType.YearMonth:
|
||||
Text = value.ToString(dateYearMonthFormat);
|
||||
break;
|
||||
case UIDateType.Year:
|
||||
Text = value.ToString(dateYearFormat);
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.Date != value)
|
||||
{
|
||||
@ -319,9 +320,51 @@ namespace Sunny.UI
|
||||
set
|
||||
{
|
||||
dateFormat = value;
|
||||
|
||||
if (ShowType == UIDateType.YearMonthDay)
|
||||
{
|
||||
Text = Value.ToString(dateFormat);
|
||||
MaxLength = dateFormat.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string dateYearMonthFormat = "yyyy-MM";
|
||||
|
||||
[Description("日期格式化掩码"), Category("SunnyUI")]
|
||||
[DefaultValue("yyyy-MM")]
|
||||
public string DateYearMonthFormat
|
||||
{
|
||||
get => dateYearMonthFormat;
|
||||
set
|
||||
{
|
||||
dateYearMonthFormat = value;
|
||||
|
||||
if (ShowType == UIDateType.YearMonth)
|
||||
{
|
||||
Text = Value.ToString(dateYearMonthFormat);
|
||||
MaxLength = dateYearMonthFormat.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string dateYearFormat = "yyyy";
|
||||
|
||||
[Description("日期格式化掩码"), Category("SunnyUI")]
|
||||
[DefaultValue("yyyy")]
|
||||
public string DateYearFormat
|
||||
{
|
||||
get => dateYearFormat;
|
||||
set
|
||||
{
|
||||
dateYearFormat = value;
|
||||
|
||||
if (ShowType == UIDateType.Year)
|
||||
{
|
||||
Text = Value.ToString(dateYearFormat);
|
||||
MaxLength = dateYearFormat.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user