c# progress bar percentage

谁都会走 提交于 2019-12-08 04:26:00

问题


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:

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#?


回答1:


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%


来源:https://stackoverflow.com/questions/14350533/c-sharp-progress-bar-percentage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!