Amateesei Roberto
Amateesei Roberto

Reputation: 1

How do I change the colour of a button when pressed and when pressed the second time to get back to the default colour?

So I made a script for a pool/snooker business and i have a page with the buttons which represents the tables. The buttons are as default green and when I press on them I want the to turn red and when pressed again to return to the default colour. If you can help me i will be grateful. Thank you very much!

Upvotes: 0

Views: 683

Answers (1)

Jon Roberts
Jon Roberts

Reputation: 2282

If WinForms then, assuming you have set button background to Green by default then:

Private Sub MyButton_Click(sender As Object, e As EventArgs) Handles MyButton.Click
    If MyButton.BackColor = Color.Green Then
        MyButton.BackColor = Color.Red
    Else
        MyButton.BackColor = Color.Green
    End If
End Sub

If not using WinForms I suspect a similar approach would work - i.e. check colour first then toggle colour based on result of that check.

Upvotes: 3

Related Questions