Browse Source

* 重构DrawString函数

pull/95/head
Sunny 2 years ago
parent
commit
0101bad8c5
  1. 6
      SunnyUI/Controls/UILight.cs
  2. 4
      SunnyUI/Controls/UITabControlMenu.cs
  3. 9
      SunnyUI/Forms/UIForm.cs

6
SunnyUI/Controls/UILight.cs

@ -20,6 +20,7 @@
* 2021-06-19: V3.0.4
* 2021-08-07: V3.0.5 线
* 2022-05-15: V3.1.8
* 2022-05-12: V3.3.6 DrawString函数
******************************************************************************/
using System;
@ -89,8 +90,9 @@ namespace Sunny.UI
/// <param name="path">绘图路径</param>
protected override void OnPaintFore(Graphics g, GraphicsPath path)
{
SizeF sf = g.MeasureString(Text, Font);
g.DrawString(Text, Font, ForeColor, Width / 2 - sf.Width / 2, Height / 2 - sf.Height / 2);
//SizeF sf = g.MeasureString(Text, Font);
//g.DrawString(Text, Font, ForeColor, Width / 2 - sf.Width / 2, Height / 2 - sf.Height / 2);
g.DrawString(Text, Font, ForeColor, ClientRectangle, TextAlign);
}
[DefaultValue(500), Description("显示间隔"), Category("SunnyUI")]

4
SunnyUI/Controls/UITabControlMenu.cs

@ -18,6 +18,7 @@
*
* 2020-01-01: V2.2.0
* 2022-08-11: V3.0.2 ItemSize
* 2022-05-12: V3.3.6 DrawString函数
******************************************************************************/
using System;
@ -377,7 +378,8 @@ namespace Sunny.UI
// 绘制标题
Color textColor = index == SelectedIndex ? tabSelectedForeColor : TabUnSelectedForeColor;
e.Graphics.DrawString(TabPages[index].Text, Font, textColor, textLeft, TabRect.Top + 2 + (TabRect.Height - sf.Height) / 2.0f);
//e.Graphics.DrawString(TabPages[index].Text, Font, textColor, textLeft, TabRect.Top + 2 + (TabRect.Height - sf.Height) / 2.0f);
e.Graphics.DrawString(TabPages[index].Text, Font, textColor, new Rectangle(textLeft, TabRect.Top, TabRect.Width, TabRect.Height), ContentAlignment.MiddleLeft);
// 绘制图标
if (ImageList != null)

9
SunnyUI/Forms/UIForm.cs

@ -45,6 +45,7 @@
* 2022-11-30: V3.3.0 RemoveAllPages函数
* 2023-01-25: V3.3.1
* 2023-02-24: V3.3.2 PageSelected可能未显示选中页面的问题
* 2022-05-12: V3.3.6 DrawString函数
******************************************************************************/
using System;
@ -1242,14 +1243,16 @@ namespace Sunny.UI
}
}
SizeF sf = e.Graphics.MeasureString(Text, TitleFont);
//SizeF sf = e.Graphics.MeasureString(Text, TitleFont);
if (TextAlignment == StringAlignment.Center)
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, (Width - sf.Width) / 2, (TitleHeight - sf.Height) / 2);
//e.Graphics.DrawString(Text, TitleFont, titleForeColor, (Width - sf.Width) / 2, (TitleHeight - sf.Height) / 2);
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(0, 0, Width, TitleHeight), ContentAlignment.MiddleCenter);
}
else
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, 6 + (ShowTitleIcon && Icon != null ? 26 : 0), (TitleHeight - sf.Height) / 2);
//e.Graphics.DrawString(Text, TitleFont, titleForeColor, 6 + (ShowTitleIcon && Icon != null ? 26 : 0), (TitleHeight - sf.Height) / 2);
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(6 + (ShowTitleIcon && Icon != null ? 26 : 0), 0, Width, TitleHeight), ContentAlignment.MiddleLeft);
}
}

Loading…
Cancel
Save