ColorDialog Class


ColorDialog Class

Namespace

System.Windows.Forms

Creatable

Yes

Description

The ColorDialog class represents a common dialog box for selecting a color. The ColorDialog class has properties that let you configure, display, and retrieve the results from this dialog box, from which the user selects a single color.

The following list discusses the more interesting members of the ColorDialog class.


AllowFullOpen Property

Configures the dialog box so that the user can define custom colors (true) or not (False). The default is true.


AnyColor Property

Configures the dialog box so that all available basic colors are displayed (true), or so that only a subset of these colors is displayed (False). The default is False.


Color Property

Upon successful use of the dialog box by the user, this property returns the selected color, an instance of the System.Drawing.Color class. This class provides access to the color in several ways. Distinct R, G, and B properties indicate the color components. The Name property returns a preconfigured name for the coloror its numeric equivalent if no name is assigned. There are also flags that provide more details about the color, such as IsKnownColor, IsNamedColor, and IsSystemColor.


CustomColors Property

An array of integer values used to define the custom colors that will be shown in the dialog box.


Reset Method

Resets the dialog box, setting all options and custom colors to their default values, and setting the selected color to black.


ShowDialog Method

Presents the dialog box to the user.


SolidColorOnly Property

For systems displaying 256 colors or less, this property, when TRue, restricts the dialog box to solid colors only.

Example

The following code asks the user for a color and displays that color:

     Dim colorSelect As New ColorDialog(  )     If (colorSelect.ShowDialog(  ) = DialogResult.OK) Then        Console.WriteLine(colorSelect.Color.ToString(  ))        Console.WriteLine(colorSelect.Color.Name)     Else        Console.WriteLine("No color chosen.")     End If 

Here is a typical example of what is returned by this code:

     Color [A=255, R=80, G=156, B=218]     ff509cda 

Version Differences

The public interfaces used for this ColorDialog class and the related VB 6 CommonDialog control are quite different.

See Also

FontDialog Class




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net