如何通过单击 VB.NET 来填充进度条?

How to fill a progress bar by clicking in VB.NET?

我在VB.Net做游戏,对进度条不熟悉。我需要一些东西,玩家需要尽可能快地按下按钮来填满进度条并进入下一个级别,或者如果速度不够快,那么 lose.I 没有代码,因为我不知道如何建立这样的东西。任何帮助都会很感激。 谢谢

假设您有一个按钮 Button1,并且您有一个进度条 ProgressBar1。

您可以使用以下代码在每次单击 Button1 时添加到进度条的值:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  If ProgressBar1.Value + 1 < ProgressBar1.Maximum Then
    ProgressBar1.Value += 1
  End If
End Sub

现在,请注意我包装增量代码的条件。这将确保用户不会超过 progressbar1 中允许的最大值。

编辑:

至于程序的其余部分,您需要使用 timer 来跟踪时间。

对于继续按钮,您将需要使用按钮上存在的 visible 属性 以便在满足某些条件之前隐藏按钮。

重新编辑:

Public Class Form1
Private intCurrentTime As Integer = 0

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  If ProgressBar1.Value + 1 < ProgressBar1.Maximum Then
    ProgressBar1.Value += 1
  End If
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  If intCurrentTime = 10 Then

    If ProgressBar1.Value = ProgressBar1.Maximum Then
      'SHOW "Proceed" BUTTON
    Else
      MsgBox("You have failed!")
    End If

    intCurrentTime = 0

  Else
    intCurrentTime += 1
  End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  Timer1.Start()
End Sub

End Class