VB如何让按钮切换?

2025-05-05 08:42:48
推荐回答(3个)
回答(1):

楼上的是正确的,我引用下
Private Sub Command2_Click()
If Command2.Caption = "开始画线" Then
'要运行的程序+这里
Command2.Caption = "返回初始"
Else
'要运行的程序+这里
Command2.Caption = "开始画线"
End If
End Sub

也可以用2个按钮来实现

Private Sub Form_Load()
Command1.Caption = "开始画线"
Command2.Caption = "返回初始"
Command2.Visible = False
End Sub
Private Sub Command2_Click()
'要运行的程序+这里
Command1.Visible = True
Command2.Visible = False
End Sub
Private Sub Command1_Click()
'要运行的程序+这里
Command2.Visible = True
Command1.Visible = False
End Sub

回答(2):

Private Sub CommandButton2_Click()
    CommandButton1.SetFocus'切换到CommandButton1
End Sub
Private Sub CommandButton1_Click()
    CommandButton2.SetFocus'切换到CommandButton2
End Sub

回答(3):

Private Sub Command2_Click()
If Command2.Caption = "开始画线" Then
Command2.Caption = "返回初始"
Else
Command2.Caption = "开始画线"
End If

End Sub