HelpProvider 類別


提供控制項的快顯畫面或線上說明。Provides pop-up or online Help for controls.

public ref class HelpProvider : System::ComponentModel::Component, System::ComponentModel::IExtenderProvider
public class HelpProvider : System.ComponentModel.Component, System.ComponentModel.IExtenderProvider
type HelpProvider = class
    inherit Component
    interface IExtenderProvider
Public Class HelpProvider
Inherits Component
Implements IExtenderProvider


下列程式碼範例示範如何使用 HelpProvider 類別,在包含四個位址欄位的表單上顯示即時線上說明。The following code example demonstrates using the HelpProvider class to display context-sensitive Help on a form containing four address fields. 此範例會使用 SetHelpString 方法來設定說明工具提示文字。The example uses the SetHelpString method to set the Help ToolTip text. 當您使用 [即時線上說明] 按鈕,並按一下 [位址] 欄位上的 [說明] 游標時,[說明工具提示] 會顯示指定的文字。When you use the context-sensitive Help button and click the Help cursor on an address field, the Help ToolTip appears with the specified text. 當您按下 F1 鍵並將焦點放在 [位址] 欄位時,會顯示 mspaint.exe 的說明檔,因為 HelpNamespace 屬性已設定為 [mspaint.exe]。When you press the F1 key with the focus in an address field, the mspaint.chm Help file is displayed because the HelpNamespace property has been set to mspaint.chm. SetShowHelp系統會針對每個位址控制項呼叫方法,以識別它有可用的說明內容。The SetShowHelp method is called for each address control to identify that it has Help content available.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public System::Windows::Forms::Form
   System::Windows::Forms::TextBox^ addressTextBox;
   System::Windows::Forms::Label ^ label2;
   System::Windows::Forms::TextBox^ cityTextBox;
   System::Windows::Forms::Label ^ label3;
   System::Windows::Forms::TextBox^ stateTextBox;
   System::Windows::Forms::TextBox^ zipTextBox;
   System::Windows::Forms::HelpProvider^ helpProvider1;
   System::Windows::Forms::Label ^ helpLabel;

      this->addressTextBox = gcnew System::Windows::Forms::TextBox;
      this->helpLabel = gcnew System::Windows::Forms::Label;
      this->label2 = gcnew System::Windows::Forms::Label;
      this->cityTextBox = gcnew System::Windows::Forms::TextBox;
      this->label3 = gcnew System::Windows::Forms::Label;
      this->stateTextBox = gcnew System::Windows::Forms::TextBox;
      this->zipTextBox = gcnew System::Windows::Forms::TextBox;
      // Help Label
      this->helpLabel->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
      this->helpLabel->Location = System::Drawing::Point( 8, 80 );
      this->helpLabel->Size = System::Drawing::Size( 272, 72 );
      this->helpLabel->Text = "Click the Help button in the title bar, then click a control to see a Help tooltip for the control.  Click on a control and press F1 to invoke the Help system with a sample Help file.";
      // Address Label
      this->label2->Location = System::Drawing::Point( 16, 8 );
      this->label2->Size = System::Drawing::Size( 100, 16 );
      this->label2->Text = "Address:";
      // Comma Label
      this->label3->Location = System::Drawing::Point( 136, 56 );
      this->label3->Size = System::Drawing::Size( 16, 16 );
      this->label3->Text = ", ";
      // Create the HelpProvider.
      this->helpProvider1 = gcnew System::Windows::Forms::HelpProvider;
      // Tell the HelpProvider what controls to provide help for, and
      // what the help String* is.
      this->helpProvider1->SetShowHelp( this->addressTextBox, true );
      this->helpProvider1->SetHelpString( this->addressTextBox, "Enter the street address in this text box." );
      this->helpProvider1->SetShowHelp( this->cityTextBox, true );
      this->helpProvider1->SetHelpString( this->cityTextBox, "Enter the city here." );
      this->helpProvider1->SetShowHelp( this->stateTextBox, true );
      this->helpProvider1->SetHelpString( this->stateTextBox, "Enter the state in this text box." );
      this->helpProvider1->SetShowHelp( this->zipTextBox, true );
      this->helpProvider1->SetHelpString( this->zipTextBox, "Enter the zip code here." );
      // Set what the Help file will be for the HelpProvider.
      this->helpProvider1->HelpNamespace = "mspaint.chm";
      // Sets properties for the different address fields.
      // Address TextBox
      this->addressTextBox->Location = System::Drawing::Point( 16, 24 );
      this->addressTextBox->Size = System::Drawing::Size( 264, 20 );
      this->addressTextBox->TabIndex = 0;
      this->addressTextBox->Text = "";
      // City TextBox
      this->cityTextBox->Location = System::Drawing::Point( 16, 48 );
      this->cityTextBox->Size = System::Drawing::Size( 120, 20 );
      this->cityTextBox->TabIndex = 3;
      this->cityTextBox->Text = "";
      // State TextBox
      this->stateTextBox->Location = System::Drawing::Point( 152, 48 );
      this->stateTextBox->MaxLength = 2;
      this->stateTextBox->Size = System::Drawing::Size( 32, 20 );
      this->stateTextBox->TabIndex = 5;
      this->stateTextBox->Text = "";
      // Zip TextBox
      this->zipTextBox->Location = System::Drawing::Point( 192, 48 );
      this->zipTextBox->Size = System::Drawing::Size( 88, 20 );
      this->zipTextBox->TabIndex = 6;
      this->zipTextBox->Text = "";
      // Add the controls to the form.
      array<System::Windows::Forms::Control^>^temp0 = {this->zipTextBox,this->stateTextBox,this->label3,this->cityTextBox,this->label2,this->helpLabel,this->addressTextBox};
      this->Controls->AddRange( temp0 );
      // Set the form to look like a dialog, and show the HelpButton.
      this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
      this->HelpButton = true;
      this->MaximizeBox = false;
      this->MinimizeBox = false;
      this->ClientSize = System::Drawing::Size( 292, 160 );
      this->Text = "Help Provider Demonstration";


int main()
   Application::Run( gcnew Form1 );

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
    private System.Windows.Forms.TextBox addressTextBox;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox cityTextBox;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox stateTextBox;
    private System.Windows.Forms.TextBox zipTextBox;
    private System.Windows.Forms.HelpProvider helpProvider1;
    private System.Windows.Forms.Label helpLabel;

    static void Main() 
        Application.Run(new Form1());

    public Form1()
        this.addressTextBox = new System.Windows.Forms.TextBox();
        this.helpLabel = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.cityTextBox = new System.Windows.Forms.TextBox();
        this.label3 = new System.Windows.Forms.Label();
        this.stateTextBox = new System.Windows.Forms.TextBox();
        this.zipTextBox = new System.Windows.Forms.TextBox();
        // Help Label
        this.helpLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.helpLabel.Location = new System.Drawing.Point(8, 80);
        this.helpLabel.Size = new System.Drawing.Size(272, 72);
        this.helpLabel.Text = "Click the Help button in the title bar, then click a control " + 
            "to see a Help tooltip for the control.  Click on a control and press F1 to invoke " +
            "the Help system with a sample Help file.";

        // Address Label
        this.label2.Location = new System.Drawing.Point(16, 8);
        this.label2.Size = new System.Drawing.Size(100, 16);
        this.label2.Text = "Address:";

        // Comma Label
        this.label3.Location = new System.Drawing.Point(136, 56);
        this.label3.Size = new System.Drawing.Size(16, 16);
        this.label3.Text = ",";

        // Create the HelpProvider.
        this.helpProvider1 = new System.Windows.Forms.HelpProvider();

        // Tell the HelpProvider what controls to provide help for, and
        // what the help string is.
        this.helpProvider1.SetShowHelp(this.addressTextBox, true);
        this.helpProvider1.SetHelpString(this.addressTextBox, "Enter the street address in this text box.");

        this.helpProvider1.SetShowHelp(this.cityTextBox, true);
        this.helpProvider1.SetHelpString(this.cityTextBox, "Enter the city here.");

        this.helpProvider1.SetShowHelp(this.stateTextBox, true);
        this.helpProvider1.SetHelpString(this.stateTextBox, "Enter the state in this text box.");

        this.helpProvider1.SetShowHelp(this.zipTextBox, true);
        this.helpProvider1.SetHelpString(this.zipTextBox, "Enter the zip code here.");

        // Set what the Help file will be for the HelpProvider.
        this.helpProvider1.HelpNamespace = "mspaint.chm";

        // Sets properties for the different address fields.

        // Address TextBox
        this.addressTextBox.Location = new System.Drawing.Point(16, 24);
        this.addressTextBox.Size = new System.Drawing.Size(264, 20);
        this.addressTextBox.TabIndex = 0;
        this.addressTextBox.Text = "";

        // City TextBox
        this.cityTextBox.Location = new System.Drawing.Point(16, 48);
        this.cityTextBox.Size = new System.Drawing.Size(120, 20);
        this.cityTextBox.TabIndex = 3;
        this.cityTextBox.Text = "";

        // State TextBox
        this.stateTextBox.Location = new System.Drawing.Point(152, 48);
        this.stateTextBox.MaxLength = 2;
        this.stateTextBox.Size = new System.Drawing.Size(32, 20);
        this.stateTextBox.TabIndex = 5;
        this.stateTextBox.Text = "";

        // Zip TextBox
        this.zipTextBox.Location = new System.Drawing.Point(192, 48);
        this.zipTextBox.Size = new System.Drawing.Size(88, 20);
        this.zipTextBox.TabIndex = 6;
        this.zipTextBox.Text = "";

        // Add the controls to the form.
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.zipTextBox, this.stateTextBox,
                                    this.label3, this.cityTextBox,
                                    this.label2, this.helpLabel,

        // Set the form to look like a dialog, and show the HelpButton.    
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        this.HelpButton = true;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.ClientSize = new System.Drawing.Size(292, 160);
        this.Text = "Help Provider Demonstration";
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private addressTextBox As System.Windows.Forms.TextBox
    Private label2 As System.Windows.Forms.Label
    Private cityTextBox As System.Windows.Forms.TextBox
    Private label3 As System.Windows.Forms.Label
    Private stateTextBox As System.Windows.Forms.TextBox
    Private zipTextBox As System.Windows.Forms.TextBox
    Private helpProvider1 As System.Windows.Forms.HelpProvider
    Private helpLabel As System.Windows.Forms.Label

    <STAThread()>  _
    Shared Sub Main()
        Application.Run(New Form1())
    End Sub
    Public Sub New()
        Me.addressTextBox = New System.Windows.Forms.TextBox()
        Me.helpLabel = New System.Windows.Forms.Label()
        Me.label2 = New System.Windows.Forms.Label()
        Me.cityTextBox = New System.Windows.Forms.TextBox()
        Me.label3 = New System.Windows.Forms.Label()
        Me.stateTextBox = New System.Windows.Forms.TextBox()
        Me.zipTextBox = New System.Windows.Forms.TextBox()

        ' Help Label
        Me.helpLabel.Location = New System.Drawing.Point(8, 80)
        Me.helpLabel.Size = New System.Drawing.Size(272, 72)
        Me.helpLabel.TabIndex = 1
        Me.helpLabel.Text = "Click the Help button in the title bar, then click a control " & _
            "to see a Help tooltip for the control.  Click on a control and press F1 to invoke " & _
            "the Help system with a sample Help file."

        ' Address Label
        Me.label2.Location = New System.Drawing.Point(16, 8)
        Me.label2.Size = New System.Drawing.Size(100, 16)
        Me.label2.Text = "Address:"

        ' Comma Label
        Me.label3.Location = New System.Drawing.Point(136, 56)
        Me.label3.Size = New System.Drawing.Size(16, 16)
        Me.label3.Text = ","

        ' Creates the HelpProvider.
        Me.helpProvider1 = New System.Windows.Forms.HelpProvider()

        ' Tell the HelpProvider what controls to provide Help for, and
        ' what the Help string is.
        Me.helpProvider1.SetHelpString(Me.addressTextBox, "Enter the street address in this text box.")
        Me.helpProvider1.SetShowHelp(Me.addressTextBox, True)

        Me.helpProvider1.SetHelpString(Me.cityTextBox, "Enter the city here.")
        Me.helpProvider1.SetShowHelp(Me.cityTextBox, True)

        Me.helpProvider1.SetHelpString(Me.stateTextBox, "Enter the state in this text box.")
        Me.helpProvider1.SetShowHelp(Me.stateTextBox, True)

        Me.helpProvider1.SetHelpString(Me.zipTextBox, "Enter the zip code here.")
        Me.helpProvider1.SetShowHelp(Me.zipTextBox, True)

        ' Sets what the Help file will be for the HelpProvider.
        Me.helpProvider1.HelpNamespace = "mspaint.chm"

        ' Set properties for the different address fields.

        ' Address TextBox
        Me.addressTextBox.Location = New System.Drawing.Point(16, 24)
        Me.addressTextBox.Size = New System.Drawing.Size(264, 20)
        Me.addressTextBox.TabIndex = 0
        Me.addressTextBox.Text = ""

        ' City TextBox
        Me.cityTextBox.Location = New System.Drawing.Point(16, 48)
        Me.cityTextBox.Size = New System.Drawing.Size(120, 20)
        Me.cityTextBox.TabIndex = 3
        Me.cityTextBox.Text = ""

        ' State TextBox
        Me.stateTextBox.Location = New System.Drawing.Point(152, 48)
        Me.stateTextBox.MaxLength = 2
        Me.stateTextBox.Size = New System.Drawing.Size(32, 20)
        Me.stateTextBox.TabIndex = 5
        Me.stateTextBox.Text = ""

        ' Zip TextBox
        Me.zipTextBox.Location = New System.Drawing.Point(192, 48)
        Me.zipTextBox.Size = New System.Drawing.Size(88, 20)
        Me.zipTextBox.TabIndex = 6
        Me.zipTextBox.Text = ""

        ' Add the controls to the form.
        Me.Controls.AddRange(New System.Windows.Forms.Control() { Me.zipTextBox, _
                                       Me.stateTextBox, Me.label3, _
                                       Me.cityTextBox, Me.label2, _
                                       Me.helpLabel, Me.addressTextBox})

        ' Set the form to look like a dialog, and show the HelpButton.    
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.HelpButton = True
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.ClientSize = New System.Drawing.Size(292, 160)
        Me.Text = "Help Provider Demonstration"

    End Sub
End Class


的每一個實例 HelpProvider 都會維護與其相關聯之控制項的參考集合。Each instance of HelpProvider maintains a collection of references to controls associated with it. 若要讓說明檔與產生關聯 HelpProvider ,請設定 HelpNamespace 屬性。To associate a Help file with the HelpProvider, set the HelpNamespace property. 您可以藉由呼叫 SetHelpNavigator 方法並提供指定控制項的值,來指定所提供的說明類型 HelpNavigatorYou specify the type of Help provided by calling the SetHelpNavigator method and providing a HelpNavigator value for the specified control. 您可以藉由呼叫方法來提供說明的關鍵字或主題 SetHelpKeywordYou provide the keyword or topic for the Help by calling the SetHelpKeyword method. 若要開啟特定主題的說明,關鍵字應以 topicName的格式傳遞。To open Help to a specific topic, the keyword should be passed in the form topicName.htm.

若要讓特定的說明字串與控制項產生關聯,請使用 SetHelpString 方法。To associate a specific Help string with a control, use the SetHelpString method. 當使用者按下 F1 鍵時,使用這個方法與控制項建立關聯的字串會顯示在快顯視窗中,而控制項則具有焦點。The string that you associate with a control using this method is displayed in a pop-up window when the user presses the F1 key while the control has focus.

如果尚未 HelpNamespace 設定屬性,您必須使用 SetHelpString 方法來提供解說文字。If the HelpNamespace property has not been set, you must use the SetHelpString method to provide the Help text. 如果您同時設定了 HelpNamespace 和說明字串,將會優先使用以為基礎的說明 HelpNamespaceIf you have set both HelpNamespace and the Help string, Help based on the HelpNamespace will take precedence.

HelpProvider 呼叫類別上的方法 Help ,以提供說明功能。HelpProvider calls methods on the Help class to provide Help functionality.



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



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

(繼承來源 Component)

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

(繼承來源 Component)

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

(繼承來源 Component)

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

(繼承來源 Component)

取得或設定數值,指定與這個 HelpProvider 物件相關的說明檔名稱。Gets or sets a value specifying the name of the Help file associated with this HelpProvider object.


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

(繼承來源 Component)

取得或設定物件,這個物件包含 HelpProvider 的相關補充資料。Gets or sets the object that contains supplemental data about the HelpProvider.



指定這個物件是否可以將它的擴充項屬性提供給指定的物件。Specifies whether this object can provide its extender properties to the specified object.


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

(繼承來源 MarshalByRefObject)

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

(繼承來源 Component)

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

(繼承來源 Component)

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

(繼承來源 Object)

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

(繼承來源 Object)

傳回指定控制項的 Help 關鍵字。Returns the Help keyword for the specified control.


傳回指定控制項的目前 HelpNavigator 設定。Returns the current HelpNavigator setting for the specified control.


傳回指定控制項的 [說明] 快顯視窗 (Pop-Up Window) 內容。Returns the contents of the pop-up Help window for the specified control.


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

(繼承來源 MarshalByRefObject)

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

(繼承來源 Component)

傳回數值,指出是否應顯示指定控制項的說明。Returns a value indicating whether the specified control's Help should be displayed.


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

(繼承來源 Object)

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

(繼承來源 MarshalByRefObject)

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

(繼承來源 Object)

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

(繼承來源 MarshalByRefObject)

移除與特定控制項關聯的說明。Removes the Help associated with the specified control.

SetHelpKeyword(Control, String)

當使用者叫用指定控制項的說明時,指定擷取說明所用的關鍵字。Specifies the keyword used to retrieve Help when the user invokes Help for the specified control.

SetHelpNavigator(Control, HelpNavigator)

從說明檔中擷取指定控制項的說明時,指定要使用的說明命令。Specifies the Help command to use when retrieving Help from the Help file for the specified control.

SetHelpString(Control, String)

指定與特定控制項相關的說明字串。Specifies the Help string associated with the specified control.

SetShowHelp(Control, Boolean)

指定特定控制項是否顯示說明。Specifies whether Help is displayed for the specified control.


傳回表示目前 HelpProvider 的字串。Returns a string that represents the current HelpProvider.



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

(繼承來源 Component)