【问题标题】:Will I be able to make progress bar repeat every time in vb6?我可以在vb6中每次重复进度条吗?
【发布时间】:2013-09-30 23:26:33
【问题描述】:

每次加载该页面时,我可以让进度条重复加载过程吗? 这是我的代码,

Private Sub Form_load()
Timer1.Interval = 50
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
PBcolor ProgressBar1, vbBlue, vbGreen
ProgressBar1 = ProgressBar1 + 1
If ProgressBar1.Value = 50 Then
ProgressBar1.Value = ProgressBar1 + 50
If ProgressBar1.Value >= ProgressBar1.Max Then
Form7.Hide
form8.Show
End If
End If
ProgressBar1.Refresh
End Sub

当我运行这段代码时,进度条首先运行,但如果我导航到另一个表单并返回(当然没有结束程序),它就不会再次运行。所以任何人都可以提出一个解决方案。谢谢。

【问题讨论】:

  • 您需要将进度条重置为最小值。刷新不会这样做。
  • 我尝试将进度条重置为“0”。但在那之后它根本不加载。表单不包含上述以外的任何代码。

标签: vb6 progress-bar


【解决方案1】:

在我的 VB6 应用程序中,我使用 UserForm_Initialize 或 UserForm_Initialize(取决于版本)。

Private Sub UserForm_Initialize()

    ProgressBar1 = 0
    'Start Progress Bar

End Sub

【讨论】:

    【解决方案2】:

    您的代码依赖于进度条值小于最大值来执行任何操作。您可以做的最简单的事情就是在表单再次获得焦点时将值重置为最小值。 Form_Activate 事件适用于此。下面我已经格式化了您的原始示例并在您的代码之后添加了新事件。

    Private Sub Form_load()
    
        Timer1.Interval = 50
        Timer1.Enabled = True
    
    End Sub
    
    Private Sub Timer1_Timer()
        On Error Resume Next
    
        PBcolor ProgressBar1, vbBlue, vbGreen
        ProgressBar1 = ProgressBar1 + 1
        If ProgressBar1.Value = 50 Then
            ProgressBar1.Value = ProgressBar1 + 50
            If ProgressBar1.Value >= ProgressBar1.Max Then
                Form7.Hide
                form8.Show
            End If
        End If
        ProgressBar1.Refresh
    End Sub
    
    'Add this to the form with the progressbar
    Private Sub Form_Activate()
    
        ProgressBar1.Value = ProgressBar1.Min
    
    End Sub
    

    【讨论】:

    • 这就是我要找的。!它解决了我的问题。谢谢你帮助我。
    【解决方案3】:

    使用 Form_Activate() 或 Form_GotFocus() 事件重置进度条并重新开始加载

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 2010-10-19
      • 2014-04-19
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多