【问题标题】:how to implement progress bar in window form如何实现窗口形式的进度条
【发布时间】:2014-05-22 11:41:21
【问题描述】:

我有一个关于窗口窗体进度条的问题。我在使用 c# 的 Windows 应用程序中有一个进度条,现在我想在单击按钮时显示进度条,但条件是单击按钮时将执行更新查询,需要 30 秒才能完成,我想显示执行查询时的进度条。我正在尝试一些代码,但没有找到解决方案。

c#

private void btnGo_Click(object sender, EventArgs e)
{
            DialogResult result = MessageBox.Show("This will update your Website. " + Environment.NewLine + "Are you Sure You want to update the Website?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (result == DialogResult.Yes)
            {
                pgbrUpdate.Visible = true;
                pgbrUpdate.MarqueeAnimationSpeed = 30;
                ExecuteQuerry();
                pgbrUpdate.Visible = false;
            }
}

【问题讨论】:

  • 您可能应该构建一个后台工作者来在执行查询期间更新进度条,当进度条被归档并且查询完成时,您可以禁用该条
  • 查看@DanielKelley 分享的链接,它引用了一些关于它的文档

标签: c# winforms progress-bar progress


【解决方案1】:

将 UpdateTask 移动到新任务(或线程)并使用计时器显示一些进度:

private void btnGo_Click(object sender, EventArgs e)
{
    DialogResult result = MessageBox.Show("This will update your Website. " + 
       Environment.NewLine + "Are you Sure You want to update the Website?", 
       "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
    if (result == DialogResult.Yes)
    {
         updateTimer.Start();
         Task.Factory.StartNew(() => ExecuteQuery());
    }
}

updateTimer_Tick()
{
   updateTimer.Value +=1;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2017-09-17
    • 1970-01-01
    • 2011-04-01
    相关资源
    最近更新 更多