ColorDialog 類別

定義

表示會顯示可用色彩的通用對話方塊,其附帶的控制項可讓使用者定義自訂色彩。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
繼承

範例

下列範例說明如何建立新的 ColorDialogThe following example illustrates the creation of new ColorDialog. 這個範例需要從 TextBox 的現有表單中呼叫方法,並將其放在其上 @no__t 1。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 類別的新執行個體。Initializes a new instance of the ColorDialog class.

屬性

AllowFullOpen

取得或設定值,指出使用者是否可以使用對話方塊來定義自訂色彩。Gets or sets a value indicating whether the user can use the dialog box to define custom colors.

AnyColor

取得或設定值,指出對話方塊是否顯示基本色彩集中的所有可用色彩。Gets or sets a value indicating whether the dialog box displays all available colors in the set of basic colors.

CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 Component)
Color

取得或設定使用者所選取的色彩。Gets or sets the color selected by the user.

Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(繼承來源 Component)
CustomColors

取得或設定對話方塊中顯示的自訂色彩集。Gets or sets the set of custom colors shown in the dialog box.

DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(繼承來源 Component)
FullOpen

取得或設定值,指出開啟對話方塊時,是否可以看到用來建立自訂色彩的控制項。Gets or sets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened.

Instance

取得基礎視窗執行個體控制代碼 (HINSTANCE)。Gets the underlying window instance handle (HINSTANCE).

Options

取得值來初始化 ColorDialogGets values to initialize the ColorDialog.

ShowHelp

取得或設定值,指出是否在色彩對話方塊中顯示 [說明] 按鈕。Gets or sets a value indicating whether a Help button appears in the color dialog box.

Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(繼承來源 Component)
SolidColorOnly

取得或設定值,指出對話方塊是否限制使用者只能選取純色。Gets or sets a value indicating whether the dialog box will restrict users to selecting solid colors only.

Tag

取得或設定包含控制項相關資料的物件。Gets or sets an object that contains data about the control.

(繼承來源 CommonDialog)

方法

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(繼承來源 Component)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

定義為了將特定功能加入通用對話方塊中而覆寫的通用對話方塊攔截程序。Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

(繼承來源 CommonDialog)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
OnHelpRequest(EventArgs)

引發 HelpRequest 事件。Raises the HelpRequest event.

(繼承來源 CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

定義為了將特定功能加入通用對話方塊中而覆寫的主控視窗 (Owner Window) 程序。Defines the owner window procedure that is overridden to add specific functionality to a common dialog box.

(繼承來源 CommonDialog)
Reset()

重設所有選項為其預設值、最後選取的色彩為黑色,以及自訂色彩為其預設值。Resets all options to their default values, the last selected color to black, and the custom colors to their default values.

RunDialog(IntPtr)

在衍生類別中覆寫時,指定通用對話方塊。When overridden in a derived class, specifies a common dialog box.

ShowDialog()

以預設的擁有人來執行通用對話方塊。Runs a common dialog box with a default owner.

(繼承來源 CommonDialog)
ShowDialog(IWin32Window)

以指定的擁有人來執行通用對話方塊。Runs a common dialog box with the specified owner.

(繼承來源 CommonDialog)
ToString()

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

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)
HelpRequest

發生於使用者按一下通用對話方塊上的 [說明] 按鈕時。Occurs when the user clicks the Help button on a common dialog box.

(繼承來源 CommonDialog)

適用於

另請參閱