JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Color Dialogs

You can see an example using Color dialogs on the CD-ROM; it's named ColorDialog. This example lets the user use a Color dialog to set the background color of a label control. In code, all you have to do is to assign the Color object returned by the dialog box's Color property to the label's BackColor property like this-I'm also changing the label's text (originally "Change my color!") to "Here's my new color!" for a little additional excitement:

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    If ColorDialog1.ShowDialog <> DialogResult.Cancel Then
        Label1.Text = "Here's my new color!"
        Label1.BackColor = ColorDialog1.Color
    End If
End Sub

The Color dialog that this example displays appears in Figure 9.6. You can use it to set the new background color of the label, as you see in Figure 9.20. You can't see it in the black-and-white figure, but I've set the background color to an appealing aqua blue there.

Figure 9.20: Setting a label's background color.
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor