diff --git a/SunnyUI/Controls/UISwitch.cs b/SunnyUI/Controls/UISwitch.cs index 2ecbdd73..b2481e37 100644 --- a/SunnyUI/Controls/UISwitch.cs +++ b/SunnyUI/Controls/UISwitch.cs @@ -24,6 +24,7 @@ * 2022-03-19: V3.1.1 重构主题配色 * 2022-09-26: V3.2.4 修复了Readonly时,双击还可以改变值的问题 * 2022-04-23: V3.3.5 增加ActiveChanging事件,在状态改变前可以进行判断 + * 2022-05-13: V3.3.6 重构DrawString函数 ******************************************************************************/ using System; @@ -270,14 +271,16 @@ namespace Sunny.UI if (!Active) { g.FillEllipse(fillColor.IsValid() ? fillColor : Color.White, 3, 3, rect.Height - 6, rect.Height - 6); - SizeF sf = g.MeasureString(InActiveText, Font); - g.DrawString(InActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + rect.Height - 6 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + //SizeF sf = g.MeasureString(InActiveText, Font); + //g.DrawString(InActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + rect.Height - 6 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + g.DrawString(InActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, new Rectangle(3 + rect.Height - 6, 0, width, rect.Height), ContentAlignment.MiddleCenter); } else { g.FillEllipse(fillColor.IsValid() ? fillColor : Color.White, Width - 3 - 1 - (rect.Height - 6), 3, rect.Height - 6, rect.Height - 6); - SizeF sf = g.MeasureString(ActiveText, Font); - g.DrawString(ActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + //SizeF sf = g.MeasureString(ActiveText, Font); + //g.DrawString(ActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + g.DrawString(ActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, new Rectangle(3, 0, width, rect.Height), ContentAlignment.MiddleCenter); } } @@ -290,14 +293,16 @@ namespace Sunny.UI if (!Active) { g.FillRoundRectangle(fillColor.IsValid() ? fillColor : Color.White, 3, 3, rect.Height - 6, rect.Height - 6, Radius); - SizeF sf = g.MeasureString(InActiveText, Font); - g.DrawString(InActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + rect.Height - 6 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + //SizeF sf = g.MeasureString(InActiveText, Font); + //g.DrawString(InActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + rect.Height - 6 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + g.DrawString(InActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, new Rectangle(3 + rect.Height - 6, 0, width, rect.Height), ContentAlignment.MiddleCenter); } else { g.FillRoundRectangle(fillColor.IsValid() ? fillColor : Color.White, Width - 3 - 1 - (rect.Height - 6), 3, rect.Height - 6, rect.Height - 6, Radius); - SizeF sf = g.MeasureString(ActiveText, Font); - g.DrawString(ActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + //SizeF sf = g.MeasureString(ActiveText, Font); + //g.DrawString(ActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, 3 + (width - sf.Width) / 2, 3 + (rect.Height - 6 - sf.Height) / 2); + g.DrawString(ActiveText, Font, fillColor.IsValid() ? fillColor : Color.White, new Rectangle(3, 0, width, rect.Height), ContentAlignment.MiddleCenter); } } } diff --git a/SunnyUI/Controls/UITreeView.cs b/SunnyUI/Controls/UITreeView.cs index fa6ed750..4a12e6ed 100644 --- a/SunnyUI/Controls/UITreeView.cs +++ b/SunnyUI/Controls/UITreeView.cs @@ -32,6 +32,7 @@ * 2022-12-06: V3.3.0 增加了可自定义行的颜色 * 2023-03-13: V3.3.3 增加MouseDoubleClick和MouseClick事件 * 2023-03-26: V3.3.4 修改LabelEdit属性 + * 2022-05-13: V3.3.6 重构DrawString函数 ******************************************************************************/ using System; @@ -1051,36 +1052,30 @@ namespace Sunny.UI { if (Painter.ContainsKey(e.Node)) { - e.Graphics.FillRectangle(Painter[e.Node].BackColor, - new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); - e.Graphics.DrawString(e.Node.Text, Font, Painter[e.Node].ForeColor, drawLeft, - e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.FillRectangle(Painter[e.Node].BackColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + //e.Graphics.DrawString(e.Node.Text, Font, Painter[e.Node].ForeColor, drawLeft, e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.DrawString(e.Node.Text, Font, Painter[e.Node].ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), ContentAlignment.MiddleLeft); } else { if (e.Node == SelectedNode) { - e.Graphics.FillRectangle(SelectedColor, - new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); - - e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, drawLeft, - e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); - + e.Graphics.FillRectangle(SelectedColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + //e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, drawLeft, e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), ContentAlignment.MiddleLeft); checkboxColor = SelectedForeColor; } else if (e.Node == CurrentNode && (e.State & TreeNodeStates.Hot) != 0) { - e.Graphics.FillRectangle(HoverColor, - new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); - e.Graphics.DrawString(e.Node.Text, Font, ForeColor, drawLeft, - e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.FillRectangle(HoverColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + //e.Graphics.DrawString(e.Node.Text, Font, ForeColor, drawLeft, e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), ContentAlignment.MiddleLeft); } else { - e.Graphics.FillRectangle(FillColor, - new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); - e.Graphics.DrawString(e.Node.Text, Font, ForeColor, drawLeft, - e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.FillRectangle(FillColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + //e.Graphics.DrawString(e.Node.Text, Font, ForeColor, drawLeft, e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); + e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), ContentAlignment.MiddleLeft); } }