我有一个周期.迭代次数取决于用户的选择.我得到的数字是double,但是进度条只接受int;
I have a cycle. the number of iterations depends on the choice of the user. I get the number of double, but the progress bar only accepts int;
double progr = 100 / (listBox2.Items.Count * listBox4.Items.Count); progressBar1.Value += progr; <- 推荐答案如果要使用进度条来显示TotalCount_n项目的处理,通常应使用以下语句:
if you want to use a progressbar to show the processing of TotalCount_n items, you would typically use this statements:
progressBar1.Maximum = TotalCount_n; progressBar1.Value = currentItem;如果您有两个进程,例如TotalCount_n和TotalCount_m,则可以编写
if you have two processes, like TotalCount_n and TotalCount_m, you can write
progressBar1.Maximum = TotalCount_n * TotalCount_m; progressBar1.Value = currentItem_n * TotalCount_m + currentItem_m;如果要使用整数计算百分比,可以编写:
if you want to calculate a percentage with an int, you can write:
int percentage = (currentItem * 100) / TotalCount_n;如果您有一个显示百分比的进程栏,则使用
if you have a processbar showing percentages, then you use
//progressBar1.Maximum = 100; // set in the designer progressBar1.Value = (currentItem * 100) / TotalCount_n;如果您的进程栏的最大值是随机的,那么您还可以编写:
if you have a processbar with a random maximum, you can also write:
progressBar1.Value = (currentItem * progressBar1.Maximum) / TotalCount_n;但是您需要注意,这个数字不会太高.因此,如果TotalCount_n和最大值都大于65000,则会溢出,因为乘积currentItem * progressBar1.Maximum可能超过2 ^ 32.
but then you need to take care, that the numbers wont get too high. so if TotalCount_n and the maximum is both higher than 65000, you will get an overflow because the product currentItem * progressBar1.Maximum might get over 2^32.
更多推荐
ProgressBar十进制值
发布评论