3 out of 6 rated this helpful - Rate this topic

ColorDialog Class

Represents a common dialog box that displays available colors along with controls that enable the user to define custom colors.

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.CommonDialog
        System.Windows.Forms.ColorDialog

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public class ColorDialog : CommonDialog

The ColorDialog type exposes the following members.

  Name Description
Public method ColorDialog Initializes a new instance of the ColorDialog class.
Top
  Name Description
Public property AllowFullOpen Gets or sets a value indicating whether the user can use the dialog box to define custom colors.
Public property AnyColor Gets or sets a value indicating whether the dialog box displays all available colors in the set of basic colors.
Protected property CanRaiseEvents Gets a value indicating whether the component can raise an event. (Inherited from Component.)
Public property Color Gets or sets the color selected by the user.
Public property Container Gets the IContainer that contains the Component. (Inherited from Component.)
Public property CustomColors Gets or sets the set of custom colors shown in the dialog box.
Protected property DesignMode Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
Protected property Events Gets the list of event handlers that are attached to this Component. (Inherited from Component.)
Public property FullOpen Gets or sets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened
Protected property Instance Infrastructure. Gets the underlying window instance handle (HINSTANCE).
Protected property Options Infrastructure. Gets values to initialize the ColorDialog.
Public property ShowHelp Gets or sets a value indicating whether a Help button appears in the color dialog box.
Public property Site Gets or sets the ISite of the Component. (Inherited from Component.)
Public property SolidColorOnly Gets or sets a value indicating whether the dialog box will restrict users to selecting solid colors only.
Public property Tag Gets or sets an object that contains data about the control. (Inherited from CommonDialog.)
Top
  Name Description
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Dispose() Releases all resources used by the Component. (Inherited from Component.)
Protected method Dispose(Boolean) Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetService Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method HookProc Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box. (Inherited from CommonDialog.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method OnHelpRequest Raises the HelpRequest event. (Inherited from CommonDialog.)
Protected method OwnerWndProc Defines the owner window procedure that is overridden to add specific functionality to a common dialog box. (Inherited from CommonDialog.)
Public method Reset Resets all options to their default values, the last selected color to black, and the custom colors to their default values. (Overrides CommonDialog.Reset().)
Protected method RunDialog Infrastructure. When overridden in a derived class, specifies a common dialog box. (Overrides CommonDialog.RunDialog(IntPtr).)
Public method ShowDialog() Runs a common dialog box with a default owner. (Inherited from CommonDialog.)
Public method ShowDialog(IWin32Window) Runs a common dialog box with the specified owner. (Inherited from CommonDialog.)
Public method ToString Infrastructure. Returns a string that represents the ColorDialog. (Overrides Component.ToString().)
Top
  Name Description
Public event Disposed Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
Public event HelpRequest Occurs when the user clicks the Help button on a common dialog box. (Inherited from CommonDialog.)
Top

The inherited member ShowDialog must be invoked to create this specific common dialog box. HookProc can be overridden to implement specific dialog box hook functionality. Use Color to retrieve the color selected by the user.

When you create an instance of ColorDialog, some of the read/write properties are set to initial values. For a list of these values, see the ColorDialog constructor.

The following example illustrates the creation of new ColorDialog. This example requires that the method is called from within an existing form that has a TextBox and Button placed on it.


private void button1_Click(object sender, System.EventArgs e)
 {
    ColorDialog MyDialog = new ColorDialog();
    // Keeps the user from selecting a custom color.
    MyDialog.AllowFullOpen = false ;
    // Allows the user to get help. (The default is false.)
    MyDialog.ShowHelp = true ;
    // Sets the initial color select to the current text color.
    MyDialog.Color = textBox1.ForeColor ;

    // Update the text box color if the user clicks OK 
    if (MyDialog.ShowDialog() == DialogResult.OK)
        textBox1.ForeColor =  MyDialog.Color;
 }
    


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ