ProgressBar十进制值

编程入门 行业动态 更新时间:2024-10-26 16:35:43
本文介绍了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十进制值

本文发布于:2023-10-09 10:30:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ProgressBar   十进制值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!