关于进度条大小(幅度) [英] Regarding progress bar size(magnitude)
本文介绍了关于进度条大小(幅度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在后台进程中使用它来指定进度条的最小值和最大值?
Is there a way to specify the minimum and maximum value of progressbar while using it through backgroundprocess?
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
int[] arr = new int[21];
for (int i = 1; i <= 20; i++)
{
arr[i] = i;
Thread.Sleep(100);
int m = (int)((1* 100)/arr.Length);
backgroundWorker1.ReportProgress(i*m);
}
}
我正在使用上面的代码和它不做这个工作..进度条永远不会达到100%,因为我只是在进行类型转换。我想将进度条的最大值设置为(arr.length),这样就不需要进行类型转换。请帮助。
I'm using the above code and it does not do the job.. The progress bar never reaches 100% as I'm just typecasting. I want to set the maximum value of progress bar to (arr.length) so that there's no need to typecast. Please help.
推荐答案
请参阅链接:
http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbar.maximum(v = vs.110).aspx [ ^ ]
为什么用数组索引处理这种方式?我会这样写:
Why are dealing that way with the array indices? I would have writeen it this way:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
int[] arr = new int[20];
double d = 100.0 / arr.Length;
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (i+1);
Thread.Sleep(100);
int p = (int) Math.Round((i+1)* d);
backgroundWorker1.ReportProgress(p);
}
}
这篇关于关于进度条大小(幅度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文