CommonDialog 類別

定義

指定用來在螢幕上顯示對話方塊的基底類別 (Base Class) 。Specifies the base class used for displaying dialog boxes on the screen.

public ref class CommonDialog abstract : System::ComponentModel::Component
public abstract class CommonDialog : System.ComponentModel.Component
type CommonDialog = class
    inherit Component
Public MustInherit Class CommonDialog
Inherits Component
繼承
衍生

範例

下列程式碼範例會使用ColorDialogCommonDialog執行, 並說明如何建立和顯示對話方塊。The following code example uses the ColorDialog implementation of CommonDialog and illustrates creating and showing a dialog box. 這個範例會要求從現有的TextBox表單中呼叫方法, 其中包含並Button放在其上。This example requires that the method is called from within an existing form, which 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

備註

RunDialogShowDialog由叫用來建立特定的通用對話方塊, 就必須執行繼承的類別。Inherited classes are required to implement RunDialog by invoking ShowDialog to create a specific common dialog box. 繼承的類別可以選擇性HookProc地覆寫, 以執行特定的對話方塊勾點功能。Inherited classes can optionally override HookProc to implement specific dialog box hook functionality.

建構函式

CommonDialog()

初始化 CommonDialog 類別的新執行個體。Initializes a new instance of the CommonDialog class.

屬性

CanRaiseEvents

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

(繼承來源 Component)
Container

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

(繼承來源 Component)
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)
Site

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

(繼承來源 Component)
Tag

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

方法

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.

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.

OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

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

Reset()

在衍生類別中覆寫時,重設通用對話方塊的屬性為其預設值。When overridden in a derived class, resets the properties of a common dialog box 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.

ShowDialog(IWin32Window)

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

ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(繼承來源 Component)

事件

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.

適用於