如果我有一個窗體Form1我只是想知道的進度條,並宣佈使用一個窗口形成遞增另一種形式
public partial class Form1 : Form
{
GraphLoadProgress loadProgress;
public Form1()
{
loadProgress = new GraphLoadProgress();
loadProgress.Show();
// do some stuff
loadProgress.progress = 25; // increment by 25%
// more stuff
for (int i = 0; i < 65; i++) // increment by 65%
{
loadProgress.progress = 1;
}
// even more stuff
loadProgress.progress = 10; // increment by 10%
// blah blah
loadProgress.progress = 100; // make sure it goes over 100%
}
}
,並在我的GraphLoadProgress形式以下
public partial class GraphLoadProgress : Form
{
public int progress { get; set; }
private void StartBackgroundWork()
{
if (Application.RenderWithVisualStyles)
progressBar.Style = ProgressBarStyle.Marquee;
else
{
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Maximum = 100;
progressBar.Value = 0;
timer1.Enabled = true;
}
//backgroundWorker.RunWorkerAsync();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar.Value > progressBar.Maximum)
this.Close();
progressBar.Increment(progress);
}
}
這顯然不工作,因爲計時器將更新和增量,即使我不想要它,有沒有什麼辦法增加進度條,並且只在進度條仍在更新時增加一定量?
友好親建議給匿名downvoters:從不downvote沒有留下評論。 – abatishchev