Need help changing the color of background

When a button is clicked, it will change the color of the background of the control. Can anyone help a beginner to actual do this?



  • The background of the button or the form? Well here's both:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Button1.BackColor = Color.DarkSalmon
    Me.BackColor = Color.Aquamarine
    End Sub

    So if you create a button called Button1, this code will change the button's colour to DarkSalmon and the form itself to Aquamarine, just play around and edit as necessary. Beware though, if you have 3d-style buttons (the default), you will notice that the border and the edge just inside the border will not change colour, if you need to colour the whole button you can set it's "FlatStyle" property to "Flat" and use the code below in addition to changing the backcolour.

    Button1.FlatAppearance.BorderColor = Color.DarkSalmon

    HTH, Dai

    Do or do not, there is no try. |
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion