* 重构DrawString函数

This commit is contained in:
Sunny 2023-05-15 22:25:51 +08:00
parent ebfaaf925c
commit 00ad2d8318

View File

@ -20,6 +20,7 @@
* 2021-09-24: V3.0.7 Column列显示方向一致 * 2021-09-24: V3.0.7 Column列显示方向一致
* 2021-11-22: V3.0.9 * 2021-11-22: V3.0.9
* 2022-09-05: V3.2.3 * 2022-09-05: V3.2.3
* 2022-05-15: V3.3.6 DrawString函数
******************************************************************************/ ******************************************************************************/
using System.Collections.Generic; using System.Collections.Generic;
@ -114,8 +115,6 @@ namespace Sunny.UI
if (str.IsNullOrEmpty()) continue; if (str.IsNullOrEmpty()) continue;
var align = column.DefaultCellStyle.Alignment; var align = column.DefaultCellStyle.Alignment;
SizeF sf = g.MeasureString(str, Font);
if (rect.Left == 0 && rect.Width == 0) continue; if (rect.Left == 0 && rect.Width == 0) continue;
switch (align) switch (align)
{ {
@ -125,11 +124,11 @@ namespace Sunny.UI
case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomLeft:
if (rect.Left == minleft && rect.Width < column.Width) if (rect.Left == minleft && rect.Width < column.Width)
{ {
g.DrawString(str, Font, ForeColor, rect.Width - column.Width, (Height - sf.Height) / 2.0f); g.DrawString(str, Font, ForeColor, new Rectangle(rect.Width - column.Width, 0, Width, Height), ContentAlignment.MiddleLeft);
} }
else else
{ {
g.DrawString(str, Font, ForeColor, rect.Left, (Height - sf.Height) / 2.0f); g.DrawString(str, Font, ForeColor, new Rectangle(rect.Left, 0, Width, Height), ContentAlignment.MiddleLeft);
} }
break; break;
@ -138,11 +137,11 @@ namespace Sunny.UI
case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomCenter:
if (rect.Left == minleft && rect.Width < column.Width) if (rect.Left == minleft && rect.Width < column.Width)
{ {
g.DrawString(str, Font, ForeColor, rect.Width - column.Width + (column.Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f); g.DrawString(str, Font, ForeColor, new Rectangle(rect.Width - column.Width, 0, column.Width, Height), ContentAlignment.MiddleCenter);
} }
else else
{ {
g.DrawString(str, Font, ForeColor, rect.Left + (column.Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f); g.DrawString(str, Font, ForeColor, new Rectangle(rect.Left, 0, column.Width, Height), ContentAlignment.MiddleCenter);
} }
break; break;
@ -151,11 +150,11 @@ namespace Sunny.UI
case DataGridViewContentAlignment.BottomRight: case DataGridViewContentAlignment.BottomRight:
if (rect.Left == minleft && rect.Width < column.Width) if (rect.Left == minleft && rect.Width < column.Width)
{ {
g.DrawString(str, Font, ForeColor, rect.Width - column.Width + column.Width - sf.Width, (Height - sf.Height) / 2.0f); g.DrawString(str, Font, ForeColor, new Rectangle(rect.Left, 0, column.Width, Height), ContentAlignment.MiddleRight);
} }
else else
{ {
g.DrawString(str, Font, ForeColor, rect.Left + column.Width - sf.Width, (Height - sf.Height) / 2.0f); g.DrawString(str, Font, ForeColor, new Rectangle(rect.Left, 0, column.Width, Height), ContentAlignment.MiddleRight);
} }
break; break;