The ColorDialog control class represents a common dialog box that displays available colors along with controls that enable the user to define custom colors. It lets the user select a color.
The main property of the ColorDialog control is Color, which returns a Color object.
The following are some of the commonly used properties of the ColorDialog control:
S.N | Property | Description |
---|---|---|
1 | AllowFullOpen | Gets or sets a value indicating whether the user can use the dialog box to define custom colors. |
2 | AnyColor | Gets or sets a value indicating whether the dialog box displays all available colors in the set of basic colors. |
3 | CanRaiseEvents | Gets a value indicating whether the component can raise an event. |
4 | Color | Gets or sets the color selected by the user. |
5 | CustomColors | Gets or sets the set of custom colors shown in the dialog box. |
6 | FullOpen | Gets or sets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened |
7 | ShowHelp | Gets or sets a value indicating whether a Help button appears in the color dialog box. |
8 | SolidColorOnly | Gets or sets a value indicating whether the dialog box will restrict users to selecting solid colors only. |
The following are some of the commonly used methods of the ColorDialog control:
S.N | Method Name | Description |
---|---|---|
1 | Reset | Resets all options to their default values, the last selected color to black, and the custom colors to their default values. |
2 | RunDialog | When overridden in a derived class, specifies a common dialog box. |
3 | ShowDialog | Runs a common dialog box with a default owner. |
The following are some of the commonly used events of the ColorDialog control:
S.N | Event | Description |
---|---|---|
1 | HelpRequest | Occurs when the user clicks the Help button on a common dialog box. |
In this example, let's change the forecolor of a label control using the color dialog box. Take the following steps:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then Label1.ForeColor = ColorDialog1.Color End If End Sub