要求:我想制作一个执行以下操作的按钮。
1)创建新表格。 2)新表格应该在任何地方都有进度条。 3)每次点击新表格从开始显示进度条处理。
请帮帮我,我被困在这一点上......我一直在努力但却无法找到出路...
private void button2_Click(object sender, EventArgs e)
{
Thread thread = new Thread(() =>
{
Download d = new Download();
d.progressBar1.Minimum = 1;
d.progressBar1.Maximum = 100;
d.Show();
for (int i = 1; i <= 100; i++)
d.progressBar1.Value = I;
});
thread.SetApartmentState(ApartmentState.STA); thread.Start();
}
答案 0 :(得分:0)
希望以下代码能够满足您的需求。您需要从其他人更新进度条。
private void button2_Click(object sender, RoutedEventArgs e)
{
Download d = new Download();
var task = Task.Factory.StartNew(() =>
{
for (int i = 1; i <= 100; i++)
{
Thread.Sleep(30);
System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
{
d.progressBar1.Value = i;
}));
}
});
d.progressBar1.Minimum = 1;
d.progressBar1.Maximum = 100;
d.Show();
}