sd_*_*ula 2 c# percentage progress-bar
我在 winform c# 应用程序中有一个进度条,我将其作为进度指示器。进度条可以有不同的最大尺寸,具体取决于用户输入的数量(可以超过 100),所以这就是我的设置方式:
this.pbLoadingWrite.Maximum = Input.Length;
this.pbLoadingWrite.Step = 1;
Run Code Online (Sandbox Code Playgroud)
然后只需更新进度条:
this.pbLoadingWrite.PerformStep();
Run Code Online (Sandbox Code Playgroud)
一切正常,但我想在进度栏顶部显示一个%数字以获得更好的可见性。
由于 Input.Length 可以 > 100,那么显示百分比的语法是什么?VS c# 中是否内置了任何辅助函数?
在这种情况下计算百分比非常容易
int percent = (progressbar1.Value / progressbar.Maximum) * 100;
Run Code Online (Sandbox Code Playgroud)
分解:
value = 56, Max = 300,
56 / 300 = 0.186666
0.186666 * 100 = 18.666%
Run Code Online (Sandbox Code Playgroud)