Visual Studio中的切换按钮(VB.NET)

时间:2014-12-26 19:09:20

标签: vb.net visual-studio-2013

我想制作一个用于暂停和启动某事的切换按钮。到目前为止,这是我的代码:

Private Sub playpause_Click(sender As Object, e As EventArgs) Handles playpause.Click
    Dim ispaused As Boolean = True
    If ispaused = True Then
        playpause.Text = "Pause"
        ispaused = False
    Else
        playpause.Text = "Play"
        ispaused = True
    End If
End Sub

文字更改为暂停,但不会更改回播放。有人可以帮助我并使其发挥作用吗?

1 个答案:

答案 0 :(得分:1)

不需要布尔值,只需检查文字:

Private Sub playpause_Click(sender As Object, e As EventArgs) Handles playpause.Click
 If playpause.Text = "Pause"
   playpause.Text = "Play"
    'do stuff for pause
 Else 'it was "Play"
   playpause.Text = "Pause"
    'do stuff for play
 End If
End Sub