我有一个 TreeView,我想在其中很好地安排我的数据。
我这样格式化我的字符串:
string name = ItemName;
string current = ("Current: " + info.Current.ToString() + " " + identifier);
string maximum = ("Maximum: " + info.Max.ToString() + " " + identifier);
string minimum = ("Minimum: " + info.Min.ToString() + " " + identifier);
string output = string.Format("{0,-20}{1,-30}{2,-30}{3,-30}{4,-30}", name, current, maximum, minimum, average);
dataNode.Text = output;
当我将 output
写入控制台时,它会按照我想要的方式打印它,就像这样(值已关闭,但这无关紧要):
Load Current: 9,23 % Maximum: 33,33 % Minimum: 6,06 % Average: 0 %
Temperature Current: 40 °C Maximum: 49 °C Minimum: 38 °C Average: 0 °C
Clock Current: 1200 Mhz Maximum: 2800,09 Mhz Minimum: 1200 Mhz Average: 0 Mhz
etc..
但是当我将完全相同的字符串打印到我的 TreeView
时,它显示如下:
我遵循了 this 上的示例页面,但这对我不起作用。
我想这与我在 TreeView
中使用的不同节点有关,但我不知道如何正确对齐我的数据。
最佳答案
看来您需要为 TreeView 设置等宽字体。
这里有一个类似的问题,例如等宽字体 (FontFamily.GenericMonospace
):
关于c# - 如何对齐 TreeView 中的列等文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37030758/