How to make a toggle button? VB NET

0

What I want is that by clicking on the button, being white, turning green, and then re-clicking it, putting it as before, and so on

IN Visual Basic

    
asked by felixAntonio 26.04.2018 в 18:44
source

1 answer

0

If you only want to make a color change of a button simulating a toggle

You can use Select Case to validate the current color of the color and change it with the event Click()

You can use the BackColor properties of the button with RGB colors and access colors from the following list Access Colors

I have an example here of how you could implement your button

Private Sub CommandButton1_Click()
'''Evento de Click

'''Selecciona la expression que deseas buscar
Select Case CommandButton1.BackColor

    '' En caso que tenga este Backcolor (16775416) cambialo por verde (4231485)
    Case 16775416
    Col = 4231485

    '''Se deja color (16775416) como default
    Case Else
    Col = 16775416

End Select 

CommandButton1.BackColor = Col  
End Sub

Here is also an example of a Toggle where you can simply use an IF in the Click event of the Toggle

Private Sub CheckBox()
''' Color por default de la propiedad BackColor
CheckBox1.BackColor = RGB(240, 255, 240)

''Si se activa el toggle cambia de color
If CheckBox1.Value = True Then
    CheckBox1.BackColor = RGB(255, 255, 255)
End If
End Sub

You could also try to specify more your question What kind of buttons are you talking about?

This I did in Excel

    
answered by 26.04.2018 в 20:00