ColorDialog ColorDialog ColorDialog ColorDialog Class

定义

表示一个通用对话框,该对话框显示可用的颜色以及允许用户定义自定义颜色的控件。Represents a common dialog box that displays available colors along with controls that enable the user to define custom colors.

public ref class ColorDialog : System::Windows::Forms::CommonDialog
public class ColorDialog : System.Windows.Forms.CommonDialog
type ColorDialog = class
    inherit CommonDialog
Public Class ColorDialog
Inherits CommonDialog
继承

示例

下面的示例演示了如何创建新ColorDialog的。The following example illustrates the creation of new ColorDialog. 此示例需要从现有窗体中调用方法TextBox , 该窗体具有并Button放置在该窗体上。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 = gcnew 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() == ::System::Windows::Forms::DialogResult::OK )
      {
         textBox1->ForeColor = MyDialog->Color;
      }
   }
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;
 }
    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim MyDialog As 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() = Windows.Forms.DialogResult.OK) Then
        TextBox1.ForeColor = MyDialog.Color
    End If
End Sub

注解

必须调用继承ShowDialog的成员才能创建此特定的公共对话框。The inherited member ShowDialog must be invoked to create this specific common dialog box. HookProc可以重写以实现特定的对话框挂钩功能。HookProc can be overridden to implement specific dialog box hook functionality. 使用Color检索用户选择的颜色。Use Color to retrieve the color selected by the user.

创建的实例ColorDialog时, 某些读/写属性被设置为初始值。When you create an instance of ColorDialog, some of the read/write properties are set to initial values. 有关这些值的列表, 请参见ColorDialog构造函数。For a list of these values, see the ColorDialog constructor.

构造函数

ColorDialog() ColorDialog() ColorDialog() ColorDialog()

初始化 ColorDialog 类的新实例。Initializes a new instance of the ColorDialog class.

属性

AllowFullOpen AllowFullOpen AllowFullOpen AllowFullOpen

获取或设置一个值,该值指示用户是否可以使用该对话框定义自定义颜色。Gets or sets a value indicating whether the user can use the dialog box to define custom colors.

AnyColor AnyColor AnyColor AnyColor

获取或设置一个值,该值指示对话框是否显示基本颜色集中可用的所有颜色。Gets or sets a value indicating whether the dialog box displays all available colors in the set of basic colors.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Color Color Color Color

获取或设置用户选定的颜色。Gets or sets the color selected by the user.

Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
CustomColors CustomColors CustomColors CustomColors

获取或设置对话框中显示的自定义颜色集。Gets or sets the set of custom colors shown in the dialog box.

DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
FullOpen FullOpen FullOpen FullOpen

获取或设置一个值,该值指示用于创建自定义颜色的控件在对话框打开时是否可见。Gets or sets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened

Instance Instance Instance Instance

获取基础窗口实例句柄 (HINSTANCE)。Gets the underlying window instance handle (HINSTANCE).

Options Options Options Options

获取用来初始化 ColorDialog 的值。Gets values to initialize the ColorDialog.

ShowHelp ShowHelp ShowHelp ShowHelp

获取或设置一个值,该值指示在颜色对话框中是否显示“帮助”按钮。Gets or sets a value indicating whether a Help button appears in the color dialog box.

Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
SolidColorOnly SolidColorOnly SolidColorOnly SolidColorOnly

获取或设置一个值,该值指示对话框是否限制用户只选择纯色。Gets or sets a value indicating whether the dialog box will restrict users to selecting solid colors only.

Tag Tag Tag Tag

获取或设置一个对象,该对象包含控件的数据。Gets or sets an object that contains data about the control.

(Inherited from CommonDialog)

方法

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr)

定义要重写的通用对话框挂钩过程,以便向通用对话框添加特定功能。Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

(Inherited from CommonDialog)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs)

引发 HelpRequest 事件。Raises the HelpRequest event.

(Inherited from CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

定义要重写的所有者窗口过程,以便向通用对话框添加特定功能。Defines the owner window procedure that is overridden to add specific functionality to a common dialog box.

(Inherited from CommonDialog)
Reset() Reset() Reset() Reset()

将所有选项重新设置为其默认值,将最后选定的颜色重新设置为黑色,将自定义颜色重新设置为其默认值。Resets all options to their default values, the last selected color to black, and the custom colors to their default values.

RunDialog(IntPtr) RunDialog(IntPtr) RunDialog(IntPtr) RunDialog(IntPtr)

在派生类中被重写时,指定通用对话框。When overridden in a derived class, specifies a common dialog box.

ShowDialog() ShowDialog() ShowDialog() ShowDialog()

用默认的所有者运行通用对话框。Runs a common dialog box with a default owner.

(Inherited from CommonDialog)
ShowDialog(IWin32Window) ShowDialog(IWin32Window) ShowDialog(IWin32Window) ShowDialog(IWin32Window)

运行具有指定所有者的通用对话框。Runs a common dialog box with the specified owner.

(Inherited from CommonDialog)
ToString() ToString() ToString() ToString()

返回表示 ColorDialog 的字符串。Returns a string that represents the ColorDialog.

事件

Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
HelpRequest HelpRequest HelpRequest HelpRequest

当用户单击通用对话框中的“帮助”按钮时发生。Occurs when the user clicks the Help button on a common dialog box.

(Inherited from CommonDialog)

适用于

另请参阅