c#进度条百分比 [英] c# progress bar percentage

查看:82
本文介绍了c#进度条百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 winform c# 应用程序中有一个进度条,我将其作为进度指示器起诉.根据用户输入的数量(可以超过 100),进度条可以有不同的最大尺寸,所以我是这样设置的:

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;

然后只需更新进度条:

this.pbLoadingWrite.PerformStep(); 

一切正常,但我想在进度条顶部显示一个 % 数字以获得更好的可见性.

All works fine but I would like to display a % number on top of the progress bar for better visibility.

由于 Input.Length 可以 > 100,显示百分比的语法是什么?是否有任何内置于 VS c# 中的辅助函数?

Since the Input.Length can be > 100, what's the syntax for displaying the percentage? Are there any helper functions built into VS c#?

推荐答案

在这种情况下计算百分比很容易

Calculating the percentage is quite easy in this case

int percent = (progressbar1.Value / progressbar.Maximum) * 100;

分解:

value = 56, Max = 300,

56 / 300 = 0.186666
0.186666 * 100 = 18.666%

这篇关于c#进度条百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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