我正在尝试格式化字符串列表,以便将项目显示为两列,每列的长度为40。为此,我正在使用下一个功能:
Private Function GetNamesString(names As List(Of String)) As String
Dim str As String = String.Empty
For i = 0 To names.Count - 2 Step 2
str += $"{names(i),-40}{names(i + 1),-40}"
str += $"{vbCrLf}"
Next
Return str
End Function
接下来我将构建消息:
Dim message As String = $"Removing master species {gbl.EditSpecies.Name} implies that next {names.Count} species must be also removed:{vbCrLf}{vbCrLf}"
message += GetNamesString(names)
message += $"{vbCrLf}{vbCrLf}Do you want to remove above species besides {gbl.EditSpecies.Name}?"
获取下一个字符串:
Removing master species Fe+3 implies that next 106 species must be also removed:
Beidellite_SBld-1(4.576H2O) Ca2Fe2O5(s)
CaFe2O4(s) C4FH13
C3FH6 Ettringite-Fe
Monosulfate-Fe Smectite_MX80(5.189H2O)
...
最后,我显示消息形式:
frmShowMessage.Show(message, "Remove species", enumMessageIcon.Warning, enumMessageButton.YesNo)
message
直接显示在标签文本中:lblMessageText.Text = message
(用于标签文本的字体类型为Arial)。
但是,我得到下一个结果:
我没有按列格式显示哪个。您知道为什么我会收到消息格式的未格式化字符串吗?
谢谢!