閱讀英文

共用方式為


HelpProvider 類別

定義

提供控制項的快顯畫面或線上說明。

C#
public class HelpProvider : System.ComponentModel.Component, System.ComponentModel.IExtenderProvider
繼承
實作

範例

下列程式碼範例示範如何使用 HelpProvider 類別,在包含四個位址欄位的表單上顯示上下文相關說明。 此範例會 SetHelpString 使用 方法來設定說明工具提示文字。 當您使用內容相關的 [說明] 按鈕,然後按一下位址欄位上的 [說明] 游標時,[說明工具提示] 會顯示具有指定文字。 當您在位址欄位中按下具有焦點的 F1 鍵時,會顯示 mspaint.chm 說明檔,因為 HelpNamespace 屬性已設定為 mspaint.chm。 系統會 SetShowHelp 針對每個位址控制項呼叫 方法,以識別其有可用的說明內容。

C#
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;

    [STAThread]
    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,
                                    this.addressTextBox});

        // 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";
    }
}

備註

的每個實例 HelpProvider 都會維護與其相關聯之控制項的參考集合。 若要建立說明檔與 的 HelpProvider 關聯,請設定 HelpNamespace 屬性。 您可以藉由呼叫 SetHelpNavigator 方法,並提供指定控制項的值,來 HelpNavigator 指定提供的 [說明] 類型。 您可以藉由呼叫 方法來提供說明的 SetHelpKeyword 關鍵字或主題。 若要開啟特定主題的說明,關鍵字應該以 topicName 格式傳遞.htm。

若要將特定說明字串與控制項產生關聯,請使用 SetHelpString 方法。 當使用者在控制項具有焦點時按下 F1 鍵時,就會在快顯視窗中顯示您使用此方法與控制項建立關聯的字串。

HelpNamespace如果尚未設定屬性,您必須使用 SetHelpString 方法來提供解說文字。 如果您同時設定 HelpNamespace [說明] 字串,則根據 HelpNamespace 的 [說明] 會優先。

HelpProvider 會呼叫 類別上 Help 的方法,以提供說明功能。

建構函式

HelpProvider()

初始化 HelpProvider 類別的新執行個體。

屬性

CanRaiseEvents

取得值,指出元件是否能引發事件。

(繼承來源 Component)
Container

取得包含 IContainerComponent

(繼承來源 Component)
DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
HelpNamespace

取得或設定數值,指定與這個 HelpProvider 物件相關的說明檔名稱。

Site

取得或設定 ComponentISite

(繼承來源 Component)
Tag

取得或設定物件,這個物件包含 HelpProvider 的相關補充資料。

方法

CanExtend(Object)

指定這個物件是否可以將它的擴充項屬性提供給指定的物件。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetHelpKeyword(Control)

傳回指定控制項的 Help 關鍵字。

GetHelpNavigator(Control)

傳回指定控制項的目前 HelpNavigator 設定。

GetHelpString(Control)

傳回指定控制項的 [說明] 快顯視窗 (Pop-Up Window) 內容。

GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetShowHelp(Control)

傳回數值,指出是否應顯示指定控制項的說明。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
ResetShowHelp(Control)

移除與特定控制項關聯的說明。

SetHelpKeyword(Control, String)

當使用者叫用指定控制項的說明時,指定擷取說明所用的關鍵字。

SetHelpNavigator(Control, HelpNavigator)

從說明檔中擷取指定控制項的說明時,指定要使用的說明命令。

SetHelpString(Control, String)

指定與特定控制項相關的說明字串。

SetShowHelp(Control, Boolean)

指定特定控制項是否顯示說明。

ToString()

傳回表示目前 HelpProvider 的字串。

事件

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱