Home > Software design >  Using ToggleButton's false .Value to remove the grey color on top when it is clicked
Using ToggleButton's false .Value to remove the grey color on top when it is clicked

Time:03-01

I'm trying to make a ToggleButton look always black but when clicked there's always this grey mask appearing on top (probably for the "clicked" effect) :

Without the grey on topWith the grey on top

I found that with the false .Value of the ToggleButton you can remove it but my problem is now that the userform I'm making appear is appearing again once closed. Is there a way to fix that ? This is my sub for when you click the button :

Private Sub ToggleButton1_Click()

    ToggleButton1.Value = False
    ToggleButton1.Caption = "Afficher l'interface"
    ToggleButton1.ForeColor = RGB(255, 255, 255)
    ToggleButton1.BackColor = RGB(0, 0, 0)
    UF_Interface.Show 'Userform I want to show when you click the button

End Sub

Thanks

CodePudding user response:

If I may suggest, if you want to use the ToggleButton,
maybe it's better making a two condition (if true then what, if false then what),
such as the image below :

enter image description here

So in the image above, if true then open the other UF - if false then close that UF.

Below is the code in the UF where the ToggleButton reside :

Private Sub UserForm_Initialize()
    With ToggleButton1
        .Caption = "OPEN UF_Interface"
        .BackColor = vbYellow
    End With
End Sub

Private Sub ToggleButton1_Click()
With ToggleButton1
    If .Value = True Then
        .Caption = "CLOSE UF_Interface"
        .BackColor = vbGreen
        UF_Interface.Show vbModeless
    Else
        .Caption = "OPEN UF_Interface"
        .BackColor = vbYellow
        Unload UF_Interface
    End If
End With
End Sub

Both userforms (UF_Interface and the one with the toggle button) must be shown in vbModeless state. So you need to make another sub in regular module, something like below :

Sub OpenFormWithToggleButton()
FormWithToggleButton.Show vbModeless
End Sub

CodePudding user response:

With the help of @karma I modified my code this way (since I couldn't change the color of a "normal" Button even though I wanted it's way of working) :

Private Sub ToggleButton1_Click()
    With ToggleButton1
        If .Value = True Then
            .Caption = "Afficher l'interface"
            .BackColor = vbBlack
            .Value = False
            UF_Interface.Show 'Userform I wanted to show
        End If
    End With
End Sub
  • Related