如何确定 .NET 中进度条的增量步骤?

发布于 2024-08-04 16:41:52 字数 325 浏览 0 评论 0原文

这看起来微不足道,但我找不到一个干净的算法。

我可以计算出我的总行数为 2186。

然后我想我会做 2186 / 100 = 21 (这将是我的 modNr) 然后我想我应该增加Backgroundworker.reportprocess()内的currentRowNr++ 并执行 if(currentRowNr % modNr == 0) 增量进度条。

进度条现在似乎表现正常,但它不会停止在 100。我预计该数字会超过最大值 100。我的算法似乎错误。

必须有一个干净的解决方案来解决这个问题,而我只是让它变得过于复杂。有数学好的人吗? ;-)

谢谢

It seems trivial, but I cant find a clean algorithm to this.

I can calculate my total rows to 2186.

Then I thought I do a 2186 / 100 = 21 (which would be my modNr)
Then I thought I would increment the currentRowNr++ inside Backgroundworker.reportprocess()
And do a if(currentRowNr % modNr == 0) increment progressbar.

The progress bar now seems to behave correctly however, it doesnt stop at 100. I get an expection that the number went over maximal of 100. My algorithm seems wrong.

There must be a clean solution for this and I am just making it overcomplicated. Anyone good in math? ;-)

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天的雪花 2024-08-11 16:41:52

将进度条的 Maximum 属性设置为 2186,Minimum 属性设置为 0。现在,每次处理过程中超过单个项目时,进度条的值都会增加 1。完全不需要算法,因为进度条将占用为你照顾。

Set the Maximum property of the progessbar to 2186 and Minimum property to 0. Now every time you got past a single item in your processing you increase the value of the progressbar by 1. Removes the need for an algorithm at all since the progessbar will take care of that for you.

℡寂寞咖啡 2024-08-11 16:41:52

显然:2121 = 101 * 21,并且2142、2163、2184也将>2142、2163、2184。 100

这是一个简单的舍入问题。
如果您使用 2186 / 100 + 1 = 22 作为 modNr,最后一次点击的结果将是 99。为了获得超精确度,请按照 Qua 的答案并重新配置进度条。

It is clear : 2121 = 101 * 21, and 2142, 2163, 2184 will also be > 100

It is a simple rounding problem.
If you use 2186 / 100 + 1 = 22 as modNr you will end up with 99 on the last hit. For ultra precision, follow Qua's answer and reconfigure the progressbar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文