gpt4 book ai didi

c# - 在循环的任何步骤中更改 Label.Text

转载 作者:行者123 更新时间:2023-11-30 13:24:22 27 4
gpt4 key购买 nike

我想在此代码中的任何步骤标签中显示该步骤的编号。在我的代码中,只显示标签中的最后一个数字!

我也 Label.Invalidate() 完成了,但是不工作。

    private void button1_Click(object sender, EventArgs e)
{
int i = 0;
while (i<100)
{
i++;
label1.Text = string.Format("Step is :{0}", i);
System.Threading.Thread.Sleep(1000);
}
}

最佳答案

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.update.aspx

设置文本后调用Update,它会帮助你。但是你当然应该考虑后台线程。

label1.Text = string.Format("Step is :{0}", i);
label1.Update();
System.Threading.Thread.Sleep(1000);

关于c# - 在循环的任何步骤中更改 Label.Text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4937838/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com