* 重构DrawString函数

This commit is contained in:
Sunny 2023-05-11 22:48:40 +08:00
parent ce0f45cc20
commit 527935aedd
2 changed files with 13 additions and 10 deletions

View File

@ -168,7 +168,8 @@ namespace Sunny.UI
g.FillPolygon(br, points.ToArray());
}
g.DrawString(Text, Font, ForeColor, (Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
//g.DrawString(Text, Font, ForeColor, (Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
g.DrawString(Text, Font, ForeColor, ClientRectangle, ContentAlignment.MiddleCenter);
}
else
{
@ -181,7 +182,7 @@ namespace Sunny.UI
width = width + Height + 6;
if (itemWidth < width) itemWidth = (int)width;
float begin = 0;
int begin = 0;
int index = 0;
foreach (var item in Items)
{
@ -237,9 +238,10 @@ namespace Sunny.UI
g.FillPolygon(br, points.ToArray());
}
g.DrawString(item.ToString(), Font, index <= ItemIndex ? ForeColor : UnSelectedForeColor, begin + (itemWidth - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
begin = begin + itemWidth - 3 - Height / 2.0f + Interval;
//g.DrawString(item.ToString(), Font, index <= ItemIndex ? ForeColor : UnSelectedForeColor, begin + (itemWidth - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
g.DrawString(item.ToString(), Font, index <= ItemIndex ? ForeColor : UnSelectedForeColor,
new Rectangle(begin, 0, itemWidth, Height), ContentAlignment.MiddleCenter);
begin = begin + itemWidth - 3 - Height / 2 + Interval;
index++;
}
}

View File

@ -319,11 +319,12 @@ namespace Sunny.UI
{
e.Graphics.SetHighQuality();
SizeF sf = e.Graphics.MeasureString(TipsText, TempFont);
float sfMax = Math.Max(sf.Width, sf.Height);
float x = Width - 1 - 2 - sfMax;
float y = 1 + 1;
e.Graphics.FillEllipse(TipsColor, x, y, sfMax, sfMax);
e.Graphics.DrawString(TipsText, TempFont, TipsForeColor, x + sfMax / 2.0f - sf.Width / 2.0f, y + sfMax / 2.0f - sf.Height / 2.0f);
int sfMax = (int)Math.Max(sf.Width, sf.Height) + 1;
int x = Width - 1 - 2 - sfMax;
int y = 1 + 1;
e.Graphics.FillEllipse(TipsColor, x - 1, y, sfMax, sfMax);
//e.Graphics.DrawString(TipsText, TempFont, TipsForeColor, x + sfMax / 2.0f - sf.Width / 2.0f, y + sfMax / 2.0f - sf.Height / 2.0f);
e.Graphics.DrawString(TipsText, TempFont, TipsForeColor, new Rectangle(x, y, sfMax, sfMax), ContentAlignment.MiddleCenter);
}
if (Focused && ShowFocusLine)