在C#中的标签框中显示多行

本文关键字:显示 标签 | 更新日期: 2024-09-23 01:33:44

我正试图检索从CheckedListBox到C#中标签的复选框索引。我可以检索到ListBox,但我更喜欢标签提供的格式自由。我拥有的代码将只显示最后一个索引,并且似乎会覆盖其他索引。

这是我的代码:

foreach (var itemListCheck1 in CheckedListBox1.CheckedIndices) {
    string item = itemListCheck1.ToString();
    messageLabel1.Text = item + "'n";
} 

显然,"''n"无法提供额外的线路。我感谢任何帮助。

在C#中的标签框中显示多行

您在每次迭代中都会覆盖标签的文本。试试这个:

messageLabel1.Text = "";
foreach (var itemListCheck1 in CheckedListBox1.CheckedIndices) {
    string item = itemListCheck1.ToString();
    messageLabel1.Text += item + "'n";
}