【发布时间】:2009-05-20 08:08:59
【问题描述】:
我刚刚使用窗口窗体应用程序设计了一个简单的“For Loop”。我希望这只能点击一次,并且如果我点击按钮,它不会重复相同的信息。我怎么能那样做?谢谢 这是我的代码:
int count;
for (count = 0; count < 5; count = count + 1)
{
listBox1.Items.Add("This is count: " + count);
}
const string textEnd = "Done!!!";
{
listBox1.Items.Add(textEnd);
}
==== 附加信息 === 我现在已经做到了。这只会单击一次,但该按钮仍处于启用状态。我觉得还可以:
int count;
for (count = 0; count < 5; count++)
{
string newItem = "This is count: " + count;
if (listBox1.Items.IndexOf(newItem) < 0)
{
listBox1.Items.Add(newItem);
}
}
const string textEnd = "Done!!!";
if (listBox1.Items.IndexOf(textEnd) <0)
{
listBox1.Items.Add(textEnd);
}
【问题讨论】:
-
建议:在 for 中声明 count 并使用 ++ 递增:for (int count = 0; count