简体   繁体   English

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

[英]Toggle Button in Visual Studio (VB.NET)

I wanted to make a toggle button for pausing and starting something. 我想制作一个切换按钮来暂停和启动某件事。 This is my code so far: 到目前为止,这是我的代码:

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

The text changes to Pause, but it doesn't change back to Play. 文本将更改为“暂停”,但不会更改回“播放”。 Can someone help me and get this to work? 有人可以帮助我并使它正常工作吗?

No boolean needed, just check the text: 不需要布尔值,只需检查文本即可:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM