| ColorDialog Class |
System.Windows.Forms
Yes
Represents a common dialog box for selecting a
The ColorDialog object has properties for setting the initial appearance and functionality of the color dialog box, a property for returning the color selected by the
The following provides a brief description of the more important members of the ColorDialog class:
Returns or sets a Boolean value indicating whether the user can use the dialog box to define custom colors. The default is True .
Returns or sets a Boolean value indicating whether the dialog box displays all available colors, although in Beta 2 of VB.NET, this property seems to have no effect. The default is False .
Returns an instance of a Color structure, which contains information about the color selected by the user. The Color structure, which is a type
Over 140 named color properties, from Red, Green, and Blue, to PapayaWhip, MistyRose, and MediumSeagreen. These properties return a Color structure.
The Name property, which returns the
The R property, G property, and B property, which return a byte specifying the red, green, or blue color component of the RGB color value, respectively.
The IsKnownColor, IsNamedColor, and IsSystemColor properties, which give information about the color.
Represents an array of Integers used to set or return the set of custom colors that will be shown in the ColorDialog dialog box.
Represents a Boolean property that sets or retrieves the value indicating whether the dialog box is opened with the controls used to create custom visible controls. (The default is False , but the user can always click the Custom Colors button to display the custom colors controls.)
Resets the dialog box by setting all options and custom colors to their default values and setting the selected color to black.
For systems displaying 256 colors or less, if this property is set to True , restricts the dialog box to solid colors only, that is, to colors that are not composites of other colors.
While the ColorDialog class is implemented in the .NET Base Class Library, VB 6
The following code asks the user for a color and displays that color:
Dim cd As New ColorDialog( )
Dim c As New Color( )
If cd.ShowDialog( ) = DialogResult.OK Then
Console.WriteLine(cd.Color.ToString)
Console.WriteLine(cd.Color.Name)
Else
Console.WriteLine("No color chosen")
End If
Note the use of the DialogResult enumeration to check user action on the dialog box. Here is the precise output if red is selected:
Color [Alpha=255, Red=255, Green=0, Blue=0] ffff0000
| COMClass Attribute |
Microsoft.VisualBasic.COMClassAttribute
Class
Adds metadata that allows a .NET class to be exposed as a COM object. You can supply the attribute with a class identifier, an interface identifier, and an event identifier. All are globally unique identifiers (GUIDs) that can be generated either by using the
New([[[ classID ], interfaceID ], eventID ])
The class identifier (CLSID) that will uniquely identify the COM class
The interface identifier (IID) that uniquely identifies the class' default COM interface
The event identifier that uniquely identifies an event
Read-only. Provides the class identifier (CLSID) that uniquely identifies a COM class. Its value is set by the classID parameter of the class constructor.
Read-only. Provides the GUID that uniquely identifies an event. Its value is set by the eventID parameter of the class constructor.
Read-only. Provides the interface identifier (IID) that uniquely identifies a COM interface. Its value is set by the interfaceID parameter of the class constructor.
Indicates whether the COM interface name is the same as the
The example defines a simple class named CContact that includes the
<ComClass>
attribute. Note that the GUIDs are in standard registry format except for the beginning and closing
<ComClass(CContact.ClassID, CContact.InterfaceID, CContact.EventID), _
Description("COM Contact Class")> Public Class CContact
Friend Const ClassID As String = _
"C7BA6669-DCFB-43d6-9A74-B1BCC6EE467B"
Friend Const InterfaceID As String = _
"72663B50-6A44-46e7-83B6-F1A4F149FF5F"
Friend Const EventID As String = _
"BD2C0D5E-C0D7-4e1e-A9E8-AD29C8003D4B"
Private sName As String
Private sCity, sState, sZip As String
Public Property Name( ) As String
Get
Return sName
End Get
Set(ByVal Value As String)
sName = Value
End Set
End Property
Public Sub New( )
MyBase.New( )
End Sub
End Class