阻止按钮直到按下特定按钮

时间:2015-01-20 15:36:50

标签: vb.net

所以,我还在学习Visual Basic,所以我不完全确定我应该搜索什么,但是我只是被赋予了一个完成取款机模拟的任务,不过我可以提交课程作品,只是为了好玩。但是,我试图找出如何阻止任何按钮,直到按下它之前的按钮。例如,我有一个模拟输入信用卡的按钮,然后是进度条。但是,我希望按钮1 - 9被阻止,直到进度条结束。我目前的代码是:

Public Class Form1

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
    txtNumber.Text = txtNumber.Text & "1"
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    barProgress.Increment(5)
    If barProgress.Value = 100 Then
        MsgBox("Please insert your pin into our secure system.")
    End If
End Sub

Private Sub btnInsertCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCard.Click
    Timer1.Start()

    If btnInsertCard.Text = "Insert Your Card" Then
        btnInsertCard.Text = "Please wait.."

    End If

End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
    txtNumber.Text = txtNumber.Text & "2"
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
    txtNumber.Text = txtNumber.Text & "3"
End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
    txtNumber.Text = txtNumber.Text & "4"
End Sub

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
    txtNumber.Text = txtNumber.Text & "5"
End Sub

Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
    txtNumber.Text = txtNumber.Text & "6"
End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
    txtNumber.Text = txtNumber.Text & "7"
End Sub

Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
    txtNumber.Text = txtNumber.Text & "8"
End Sub

Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
    txtNumber.Text = txtNumber.Text & "9"
End Sub

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
    txtNumber.Text = txtNumber.Text & "0"
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    txtNumber.Clear()
End Sub

结束班

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

我认为您想要使用的是.Enabled属性。

在Form1_Load中,我将所有按钮的.Enabled属性设置为False

一旦barProgress.Value = 100我停止计时器并启用第一个按钮。

然后在每个按钮的点击事件中,我将下一个按钮的.Enabled属性设置为True

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim buttonArray = {btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0}

    For Each button In buttonArray
        button.Enabled = False
    Next
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
    txtNumber.Text = txtNumber.Text & "1"
    btn2.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    barProgress.Increment(5)
    If barProgress.Value = 100 Then
        Timer1.Stop()
        btn1.Enabled = True
        MsgBox("Please insert your pin into our secure system.")
    End If
End Sub

Private Sub btnInsertCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCard.Click
    Timer1.Start()

    If btnInsertCard.Text = "Insert Your Card" Then
        btnInsertCard.Text = "Please wait.."

    End If

End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
    txtNumber.Text = txtNumber.Text & "2"
    btn3.Enabled = True
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
    txtNumber.Text = txtNumber.Text & "3"
    btn4.Enabled = True
End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
    txtNumber.Text = txtNumber.Text & "4"
    btn5.Enabled = True
End Sub

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
    txtNumber.Text = txtNumber.Text & "5"
    btn6.Enabled = True
End Sub

Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
    txtNumber.Text = txtNumber.Text & "6"
    btn7.Enabled = True
End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
    txtNumber.Text = txtNumber.Text & "7"
    btn8.Enabled = True
End Sub

Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
    txtNumber.Text = txtNumber.Text & "8"
    btn9.Enabled = True
End Sub

Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
    txtNumber.Text = txtNumber.Text & "9"
    btn0.Enabled = True
End Sub

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
    txtNumber.Text = txtNumber.Text & "0"
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    'txtNumber.Clear()
    txtNumber.Text = Nothing
End Sub

End Class

*编辑 - 抱歉,我以某种方式读错了你的问题。纠正了我的回答。