VB - 进度条没有增加正确的数量? [英] VB - progress bar not incrementing correct amounts?
问题描述
我有一个包含一些变量的程序.我正在尝试与变量进行交互,并通过使用它们来增加进度条使它们显示时间的视觉视角.
I've got a program that's got some variables. I'm trying to interact the variables and make them show a visual perspective of time by using them to increment the progress bar.
代码的再现:
Dim count As Integer = ListBox1.Items.Count
Dim _toProgress As Integer = 100 / count
ProgressBar1.Increment(_toProgress)
我把这一切都放在一个循环中,所以在一个进程(循环中)完成后添加了_toProgress"...
I've got this all in a loop, so "_toProgress" is added on after a process (in a loop) has been completed...
这基本上就是我简化的代码.问题是当我增加进度条时,它在它应该完成之前完成了.
That's basically the code I have simplified. The problem is that when I increment the progress bar, it finished before it's supposed to.
例如:我有一个循环完成 175 个过程:100/175 = 0.5714285714285714所以,_toProgress 应该等于'0.5714285714285714'.一旦其中一个进程完成,它就会将_toProgress"添加到增量中 (ProgressBar1.Increment(_toProgress)).
e.g: I've got a loop completing 175 process: 100 / 175 = 0.5714285714285714 So, _toProgress should equal '0.5714285714285714'. Once one of the processes has been completed, it adds '_toProgress' to the incrementation (ProgressBar1.Increment(_toProgress)).
我知道 '_toProgress' 整数是正确的,因为 '0.5714285714285714' * 175 = 100.
I know the '_toProgress' integer is correct, because '0.5714285714285714' * 175 = 100.
所以我不知道为什么进度条会提前完成,有什么线索吗?
So I have no clue why the progress bar completes before it's supposed to, any clues?
推荐答案
您只能以整数增量递增 ProgressBar.
You can only increment a ProgressBar in Integer increments.
最简单的解决方案是将 ProgressBar 的 Maximum
属性更改为您拥有的进程数,然后增加 1.
The easiest solution is to change the Maximum
property of the ProgressBar to the number of processes that you have and then increment by 1.
例如:
ProgressBar1.Maximum = ListBox1.Items.Count
ProgressBar1.Increment(1)
这篇关于VB - 进度条没有增加正确的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!