【问题标题】:How to fill a progress bar by clicking in VB.NET?如何通过单击 VB.NET 来填充进度条?
【发布时间】:2015-06-09 20:04:07
【问题描述】:

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

【问题讨论】:

  • 你在 windows 窗体中工作吗?

标签: vb.net click progress-bar


【解决方案1】:

假设您有一个按钮 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

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

编辑:

至于程序的其余部分,您需要使用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

【讨论】:

  • 如果您需要进一步解释,请告诉我!
  • 感谢您的快速响应,是的,我正在使用 Windows 窗体,但我仍然不知道如何在特定时间内填写进度条,例如在 10 秒内填满该栏,然后显示“继续”按钮以进入下一个级别。如果进度条在 10 秒内没有填满,玩家将输。
  • 您的问题是如何通过点击来填充进度条,我回答了这个问题;你现在要求一个完整的程序。我很乐意帮助您解决您遇到的问题,但您必须展示您的尝试或将您的问题分解成更小的部分。
  • 我需要帮助将计时器与进度条结合起来,因为它对我的知识来说太复杂了。
  • 检查我的新编辑。这基本上就是您的程序,不过您必须对其进行最后润色。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-16
  • 2019-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-19
相关资源
最近更新 更多