JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Setting a Button's Foreground and Background Color

You've got your program running at last—but now the Aesthetic Design department is on the phone. The "emergency" window in your program is colored red—why not also the PANIC button in the middle of that window? So how do you do that?

You use the button's Background property. Here, I'm setting the background color of a button at design time, and three sets of colors are available: a set of standard Visual Basic System colors, Web colors, and a palette of custom colors, as shown in Figure 6.6.

Click To expand
Figure 6.6: Setting a button's background color.

You also can set the button's Background property at run time, setting it to a color value, such as those in the Visual Basic Color enumeration. Here, I'm setting a button's background to blue:

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

You can also set the foreground color of a button—the color of the caption's text. Much like the BackColor property, you can set a button's ForeColor property at design time, or at run time, like this:

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Button1.ForeColor = Color.Red
End Sub
Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor