HeaderPane
Main
Hide
Share Link
Print

Color Dialog

SftColorDialog is a color dialog in the mode of the application's SftStyle component: light, dark or with the colors of the Windows contrast theme. It is a component with the properties of the Windows Forms ColorDialog and is shown the same way, with ShowDialog, so a ColorDialog is replaced by changing its class name. It is added to a form from the Toolbox, or created in code.

The left side of the dialog offers colors to pick. Basic shows the 48 basic colors of the Windows color dialog, Named the named colors of .NET (Color.CornflowerBlue and the others) and System the system colors; below them are 16 custom colors. The right side, the color editor, which appears after a click on Define Custom Colors >> or with SftColorDialog.FullOpen, defines a color with a saturation and brightness area and a hue strip, fields for its hexadecimal value, red, green and blue, hue, saturation and value (brightness), and Pick, which takes the color of any point on the screen: after a click on Pick, the color follows the mouse until the next click, and Esc ends picking with the color last under the mouse. The texts of the dialog are English, except the OK, Cancel and Help buttons, which come in the language of Windows.

C#

sftColorDialog1.Color = panelPreview.BackColor;
if (sftColorDialog1.ShowDialog(this) == DialogResult.OK)
    panelPreview.BackColor = sftColorDialog1.Color;

VB

SftColorDialog1.Color = PanelPreview.BackColor
If SftColorDialog1.ShowDialog(Me) = DialogResult.OK Then
    PanelPreview.BackColor = SftColorDialog1.Color
End If
MemberDescription
SftColorDialog.ColorThe color shown when the dialog opens and, after OK, the color the user chose (Color.Black by default).
SftColorDialog.CustomColorsThe 16 custom colors as BGR values (0x00BBGGRR), as the Windows Forms ColorDialog uses them. After OK they hold the custom colors the user defined; an application that keeps them between runs saves and restores this array.
SftColorDialog.AllowFullOpenWhether the user can open the color editor with Define Custom Colors >> (True by default).
SftColorDialog.FullOpenShows the color editor when the dialog opens (False by default); without AllowFullOpen it is not shown.
SftColorDialog.AllowAlphaAdds an opacity strip and an Alpha field, so the user can choose a partially transparent color (False by default); the hexadecimal field then shows and takes eight digits, #RRGGBBAA, with the opacity last. Without AllowAlpha the dialog starts from the opaque SftColorDialog.Color and returns an opaque color.
SftColorDialog.SolidColorOnlyMakes the chosen color fully opaque, also with AllowAlpha (False by default). A named or system color stays as it is.
SftColorDialog.ShowHelpShows a Help button, which raises the HelpRequest event of the dialog (False by default).
SftColorDialog.AnyColorKept for compatibility with the Windows Forms ColorDialog; the dialog always shows all colors.
SftColorDialog.ResetResets all properties to their default values.

Add to Custom Colors puts the edited color, made opaque, into the selected custom color, or the first one, and selects the next.

Named and System Colors

A named color or a system color the user picks and does not change is returned as that color, for example Color.CornflowerBlue or SystemColors.Window, not as its RGB value. A control that is given SystemColors.Window as its back color keeps it translated to the dark counterpart in dark mode, as every control with a system color is (see Standard Controls). Once the user changes the color in the editor, the dialog returns the RGB value.

The Mode of the Dialog

The dialog uses the mode of the application's SftStyle component (SftStyle.DarkModeActive and SftStyle.HighContrastActive). A color dialog placed with the Visual Studio designer carries the license in its SftColorDialog.Contents property; one created in code is licensed by the application's SftStyle component (see Licensing and Contents).