我正在尝试使用进度条,但它没有正确显示弹出窗口。当我使用msgbox时,它出现了100次,当我使用form2替换msgbox时,它会一直显示,即使我关闭它。
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(1)
If ProgressBar1.Value = ProgressBar1.Maximum Then
MsgBox("Done")
End If
End Sub
End Class
答案 0 :(得分:1)
如果您只想显示一次消息,请在消息框
之前停止计时器Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(1)
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Stop()
MsgBox("Done")
End If
End Sub
答案 1 :(得分:0)
这是因为您不是disable
或Stop
计时器。当ProgressBar1.Value
达到最大值时,消息框将显示为"Done"
但是计时器仍在执行,因此您将获得消息,直到计时器被禁用,因为条件If ProgressBar1.Value = ProgressBar1.Maximum Then
为真。所以如果条件为真,你需要禁用定时器。
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Enabled = False
MsgBox("Done")
End If
或者您可以使用Timer1.Stop()