如何确定 .NET 中进度条的增量步骤?
这看起来微不足道,但我找不到一个干净的算法。
我可以计算出我的总行数为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将进度条的 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.
显然: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.