ProgressBar十进制值 [英] ProgressBar decimal value

查看:46
本文介绍了ProgressBar十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个周期.迭代次数取决于用户的选择.我得到的数字是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十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆