一个Command怎么可以有俩种功能啊?原来是打开,按了后变成关闭

解决方案 »

  1.   

    Private Sub Command1_Click()
        With Command1
             If .Caption = "打开" Then
                .Caption = "关闭"
                 '打开代码 ...
            Else
                .Caption = "打开"
                '关闭代码 ...
            End If
         End With
    End Sub
      

  2.   

    '另外一个怪招,当然楼上的是正解,还可以将两个command叠放到一起:Private Sub Command1_Click()
    Command1.Visible = False
    Command2.Visible = True
    '你的代码
    End SubPrivate Sub Command2_Click()
    Command2.Visible = False
    Command1.Visible = True
    '你的代码
    End Sub
      

  3.   

    这个还是比较简单的,方法很多
    读取属性和设变量都是方法
    Private commandBl As Boolean  
    Private Sub Command1_Click()
    if commandbl = false then
    msgbox “打开"
    commandbl=true
    else
    msgbox “关闭"
    commandbl=false
    end if
      

  4.   

    Private Sub Command5_Click()
    If Command5.Caption = "打开端口" Then
    Text13.Text = Now & "成功打开端口"
    Command5.Caption = "关闭端口"
    ElseIf Command5.Caption = "关闭端口" Then
    Text13.Text = Now & "成功关闭端口"
    Command5.Caption = "打开端口"
    End If
    End Sub
    怎么可以让text中的内容一直显示 热不被后面的所覆盖 
    例如:[2011-05-27 10:49:34 342]  成功打开端口
    [2011-05-27 10:49:34 576]  成功关闭端口
    [2011-05-27 10:49:34 733]  成功打开端口
    [2011-05-27 10:49:34 920]  成功关闭端口
      

  5.   


    Private Sub Command5_Click()text3.multiline=true
    text3.text=""If Command5.Caption = "打开端口" Then
    Text13.Text = text3.text & vbcrlf & Now & "成功打开端口"
    Command5.Caption = "关闭端口"
    ElseIf Command5.Caption = "关闭端口" Then
    Text13.Text =text3.text & vbcrlf &  Now & "成功关闭端口"
    Command5.Caption = "打开端口"
    End If
    End Sub
      

  6.   

    Private Sub Command1_Click()
    Command1.Visible = False
    Command2.Visible = True
    .............
    End SubPrivate Sub Command2_Click()
    Command2.Visible = False
    Command1.Visible = True
    ..............
    End Sub
    很好
      

  7.   

    不用 CommandButton,换成 ToggleButton ,切换按钮控件:
     
    Private Sub ToggleButton_Click()
        With ToggleButton
            If .Value Then
                .Caption = "关闭"
            Else
                .Caption = "打开"
            End If
        End With
    End Sub多简单。