【发布时间】:2017-02-08 14:37:45
【问题描述】:
问题是标签在progress-bar 完成之前显示。如何让label 仅在progress-bar 完全完成后显示?
我尝试将最大值更改为更高的数字,但没有成功。
public partial class dload : Form
{
public dload()
{
InitializeComponent();
}
private void dload_Load(object sender, EventArgs e)
{
label1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
progressBar1.Minimum = 0;
progressBar1.Maximum = 5000;
for (i = 0; i <= 5000; i++)
{
progressBar1.Value = i;
if (i == 5000)
{
label1.Visible = true;
}
}
}
}
【问题讨论】:
-
首先,您的循环只会运行到 5000。您不需要循环内的
if。删除 while 子句,仅将label1.Visible = true;放在循环下方。现在,就您而言,进度条已完成,但 UI 尚未完全更新。我认为您可以在更新值后输入progressBar1.Refresh()。 edit 刚刚运行了这段代码,看到了你的意思。这很奇怪。需要调查并回复您 -
你为什么不设置'label1.Visible = true;'在'for'循环之后?
-
您不需要 if 语句。只需将 label1.Visible 移动到循环之后。
标签: c# winforms progress-bar