在 WPF 中对齐字符串
Aligining Strings In WPF
我想打印这样的数据:
http://www.csharp-examples.net/align-string-with-spaces/
-------------------------------
Bi1l | Gates | 51
EdnA | Parker | 114
JohNny | Depp | 44
-------------------------------
我尝试使用上面的例子,PadRight
和 PadLeft
以及更多的长度计算,我总是得到这种类型的输出(我的输出是 TextBox
)
-------------------------------
Bill | Gates | 51
Edna | Parker | 114
Johnny | Depp | 44
-------------------------------
据我所知,这是因为 WPF 没有为每个字符提供固定且相等的块,因此 W
比 i
需要更多 space,并使分离看起来很糟糕。
有人可以帮我解决吗?
您可以将字体类型更改为 Monospace font (Wikipedia),例如 Courier
。
根据链接的维基百科文章,其他可能的字体类型是 Courier New
、Lucida Console
、Monaco
或 Consolas
。
或者,您可以更改 UI 并使用某种网格控件显示数据,例如 DataGrid 控件来显示数据。
我想打印这样的数据:
http://www.csharp-examples.net/align-string-with-spaces/
------------------------------- Bi1l | Gates | 51 EdnA | Parker | 114 JohNny | Depp | 44 -------------------------------
我尝试使用上面的例子,PadRight
和 PadLeft
以及更多的长度计算,我总是得到这种类型的输出(我的输出是 TextBox
)
------------------------------- Bill | Gates | 51 Edna | Parker | 114 Johnny | Depp | 44 -------------------------------
据我所知,这是因为 WPF 没有为每个字符提供固定且相等的块,因此 W
比 i
需要更多 space,并使分离看起来很糟糕。
有人可以帮我解决吗?
您可以将字体类型更改为 Monospace font (Wikipedia),例如 Courier
。
根据链接的维基百科文章,其他可能的字体类型是 Courier New
、Lucida Console
、Monaco
或 Consolas
。
或者,您可以更改 UI 并使用某种网格控件显示数据,例如 DataGrid 控件来显示数据。