c#进度条百分比
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14350533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
c# progress bar percentage
提问by sd_dracula
I have a progress bar in a winform c# application and I sue that as a progress indicator. The progress bar can have a different Maximum size depending on the amount of user input (which can go over 100) so this is how I set it up:
我在 winform c# 应用程序中有一个进度条,我将其作为进度指示器起诉。根据用户输入的数量(可以超过 100),进度条可以有不同的最大大小,所以我是这样设置的:
this.pbLoadingWrite.Maximum = Input.Length;
this.pbLoadingWrite.Step = 1;
then just update the progress bar with:
然后只需更新进度条:
this.pbLoadingWrite.PerformStep();
All works fine but I would like to display a % number on top of the progress bar for better visibility.
一切正常,但我想在进度条顶部显示一个 % 数字以获得更好的可见性。
Since the Input.Length can be > 100, what's the syntax for displaying the percentage? Are there any helper functions built into VS c#?
由于 Input.Length 可以 > 100,显示百分比的语法是什么?是否有任何内置于 VS c# 的辅助函数?
采纳答案by sa_ddam213
Calculating the percentage is quite easy in this case
在这种情况下计算百分比很容易
int percent = (progressbar1.Value / progressbar.Maximum) * 100;
Break down:
分解:
value = 56, Max = 300,
56 / 300 = 0.186666
0.186666 * 100 = 18.666%