正如上面的評論者所說,實際使用控件創建列表會更清潔,但如果必須的話,您可以使用字符串來完成。
使用string.Format
,你可以墊在使用爲右對齊文本正值一定的寬度和負左對齊:
https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx
在這個頁面:
int[] years = { 2013, 2014, 2015 };
int[] population = { 1025632, 1105967, 1148203 };
String s = String.Format("{0,-10} {1,-10}\n\n", "Year", "Population");
for(int index = 0; index < years.Length; index++)
s += String.Format("{0,-10} {1,-10:N0}\n",
years[index], population[index]);
// Result:
// Year Population
//
// 2013 1,025,632
// 2014 1,105,967
// 2015 1,148,203
如果在WPF,爲什麼使用這個TextBox?一個ItemsControl會爲你提供更好的服務。即使在WinForms中你也有更好的選擇 – BradleyDotNET
剛添加標籤「winforms」。 – VAAA