在任务栏中显示进度条我做错了什么?
在我上一篇文章之后,我试图完成这项工作
,我有以下代码(已编辑):
public partial class Form1 : Form
{
...
private TaskDialog Taskbar = new TaskDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
Taskbar.ProgressBar.Value = progressBar1.Value;
}
private void button2_Click(object sender, EventArgs e)
{
bgWorker.RunWorkerAsync();
}
bgWorker_dowork()
{
timer1.Enabled = true;
timer1.Start();
while(progressBar1.Value < progressBar1.Maximum)
{
progressBar1.Value++;
}
}
我做错了什么?
编辑:我无法让它在任务栏上最小化时显示进度条,尽管我做了建议的更改。
Following my previous post iam trying to make this work
I have the following code (Edited):
public partial class Form1 : Form
{
...
private TaskDialog Taskbar = new TaskDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
Taskbar.ProgressBar.Value = progressBar1.Value;
}
private void button2_Click(object sender, EventArgs e)
{
bgWorker.RunWorkerAsync();
}
bgWorker_dowork()
{
timer1.Enabled = true;
timer1.Start();
while(progressBar1.Value < progressBar1.Maximum)
{
progressBar1.Value++;
}
}
What am i doing wrong?
Edit: i cant make it show a progressbar while minimized on the taskbar, althought i did the changes suggested..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是因为您阻塞了 GUI 线程,
这将导致它锁定并阻止它更新 UI。
永远不要在主线程上运行这样的循环,使用 BackGroundWorker 来处理类似的事情。
That's because you're blocking your GUI thread
This will cause it to lock and prevent it from updating the UI.
Never run such loops on your main thread, use a
BackGroundWorker
for stuff like that.确保进度条的值不应超过最大值。
ProgressBar.Maximum 属性
ProgressBar.Minimum属性
Make sure the value of the Progress Bar should not exceed the Maximum Value.
ProgressBar.Maximum Property
ProgressBar.Minimum Property