新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Form_Load()
Command1.Tag = "0" '还没启动,是停止状态
Command1.Caption = "启动"
End Sub
Private Sub Command1_Click()
'启动与停止服务切换
With Command1
If .Tag = "0" Then
.Tag = "1" '现在是停止状态->设置为启动状态
.Caption = "停止"
MsgBox "程序开始运行..."
Else
.Tag = "0" '现在是启动状态->设置为停止状态
.Caption = "启动"
MsgBox "程序现在停止了。"
End If
End With
End Sub
这样就可以一个按钮切换开关。