閱讀英文

共用方式為


Help 類別

定義

封裝 HTML Help 1.0 引擎。

C#
public class Help
C#
public static class Help
繼承
Help

範例

下列程式碼範例會顯示一個表單,其中包含三個按鈕,可用來與 Mspaint.chm 說明檔互動。 [ 顯示說明索引 ] 按鈕會顯示 [說明] 檔案的 [ 索引] 索引卷 標。 [ 顯示說明 ] 按鈕會根據 [說明 導覽器 ] 清單中選取的值,顯示 [說明] 檔案中的內容。 [ 顯示關鍵字 ] 按鈕會根據 [ 關鍵字 ] 文字方塊中指定的關鍵字,在 [說明檔] 中顯示內容。

例如,若要依索引值顯示橢圓說明頁面,請在 [說明導覽器] 下拉式清單中選取 HelpNavigator.KeywordIndex 值,在 [參數] 文字方塊中輸入橢圓,然後按一下 [顯示說明] 按鈕。 若要依關鍵字顯示「使用筆刷繪製」說明主題,請在 [關鍵字] 文字方塊中輸入mspaint.chm::/paint_brush.htm,然後按一下 [顯示關鍵字] 按鈕。

此範例會 ShowHelp 使用 方法來顯示不同的 [說明] 索引標籤和 [說明] 主題,以及 ShowHelpIndex 顯示說明索引的方法。

C#
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
    private const string helpfile = "mspaint.chm";
    private System.Windows.Forms.Button showIndex;
    private System.Windows.Forms.Button showHelp;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.ComboBox navigatorCombo;
    private System.Windows.Forms.Button showKeyword;
    private System.Windows.Forms.TextBox keyword;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox parameterTextBox;

    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        this.showIndex = new System.Windows.Forms.Button();
        this.showHelp = new System.Windows.Forms.Button();
        this.navigatorCombo = new System.Windows.Forms.ComboBox();
        this.label1 = new System.Windows.Forms.Label();
        this.showKeyword = new System.Windows.Forms.Button();
        this.keyword = new System.Windows.Forms.TextBox();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.parameterTextBox = new System.Windows.Forms.TextBox();

        // Help Navigator Label
        this.label1.Location = new System.Drawing.Point(112, 64);
        this.label1.Size = new System.Drawing.Size(168, 16);
        this.label1.Text = "Help Navigator:";

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

        // Parameter Label
        this.label3.Location = new System.Drawing.Point(112, 120);
        this.label3.Size = new System.Drawing.Size(168, 16);
        this.label3.Text = "Parameter:";

        // Show Index Button
        this.showIndex.Location = new System.Drawing.Point(16, 16);
        this.showIndex.Size = new System.Drawing.Size(264, 32);
        this.showIndex.TabIndex = 0;
        this.showIndex.Text = "Show Help Index";
        this.showIndex.Click += new System.EventHandler(this.showIndex_Click);

        // Show Help Button
        this.showHelp.Location = new System.Drawing.Point(16, 80);
        this.showHelp.Size = new System.Drawing.Size(80, 80);
        this.showHelp.TabIndex = 1;
        this.showHelp.Text = "Show Help";
        this.showHelp.Click += new System.EventHandler(this.showHelp_Click);

        // Show Keyword Button
        this.showKeyword.Location = new System.Drawing.Point(16, 192);
        this.showKeyword.Size = new System.Drawing.Size(88, 32);
        this.showKeyword.TabIndex = 4;
        this.showKeyword.Text = "Show Keyword";
        this.showKeyword.Click += new System.EventHandler(this.showKeyword_Click);

        // Help Navigator ComboBox
        this.navigatorCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.navigatorCombo.Location = new System.Drawing.Point(112, 80);
        this.navigatorCombo.Size = new System.Drawing.Size(168, 21);
        this.navigatorCombo.TabIndex = 2;

        // Keyword TextBox
        this.keyword.Location = new System.Drawing.Point(120, 200);
        this.keyword.Size = new System.Drawing.Size(160, 20);
        this.keyword.TabIndex = 5;
        this.keyword.Text = "";

        // Parameter TextBox
        this.parameterTextBox.Location = new System.Drawing.Point(112, 136);
        this.parameterTextBox.Size = new System.Drawing.Size(168, 20);
        this.parameterTextBox.TabIndex = 8;
        this.parameterTextBox.Text = "";

        // Set up how the form should be displayed and add the controls to the form.
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                        this.parameterTextBox, this.label3,
                                        this.label2, this.keyword,
                                        this.showKeyword, this.label1,
                                        this.navigatorCombo, this.showHelp,
                                        this.showIndex});
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        this.Text = "Help App";

        // Load the various values of the HelpNavigator enumeration
        // into the combo box.
        TypeConverter converter;
        converter = TypeDescriptor.GetConverter(typeof(HelpNavigator));
        foreach(object value in converter.GetStandardValues()) 
        {
            navigatorCombo.Items.Add(value);
        }
    }

    private void showIndex_Click(object sender, System.EventArgs e)
    {
        // Display the index for the help file.
        Help.ShowHelpIndex(this, helpfile);
    }
    private void showHelp_Click(object sender, System.EventArgs e)
    {
        // Display Help using the Help navigator enumeration
        // that is selected in the combo box. Some enumeration
        // values make use of an extra parameter, which can
        // be passed in through the Parameter text box.
        HelpNavigator navigator = HelpNavigator.TableOfContents;
        if (navigatorCombo.SelectedItem != null)
        {
            navigator = (HelpNavigator)navigatorCombo.SelectedItem;
        }
        Help.ShowHelp(this, helpfile, navigator, parameterTextBox.Text);
    }
    private void showKeyword_Click(object sender, System.EventArgs e)
    {
        // Display help using the provided keyword.
        Help.ShowHelp(this, helpfile, keyword.Text);
    }
}

備註

您無法建立 類別的新實例 Help 。 若要為應用程式提供說明,請呼叫靜態 ShowHelpShowHelpIndex 方法。

您可以使用 Help ,以 HTML 說明格式顯示已編譯的說明檔 (.chm) 或 HTML 檔案。 已編譯的說明檔提供頁面的目錄、索引、搜尋功能及關鍵字連結。 快捷方式只適用于已編譯的說明檔。

您可以使用 HTML 說明工作坊產生 HTML 說明 1.x 檔案。 For more information about HTML Help, see "HTML Help Workshop" and other HTML Help topics at Microsoft HTML Help.

方法

ShowHelp(Control, String)

在指定的 URL 顯示說明檔的內容。

ShowHelp(Control, String, HelpNavigator)

顯示特定主題在指定 URL 中找到的說明檔內容。

ShowHelp(Control, String, HelpNavigator, Object)

顯示 URL 中使用者提供的說明檔內容。

ShowHelp(Control, String, String)

顯示特定關鍵字在指定的 URL 中找到的說明檔內容。

ShowHelpIndex(Control, String)

顯示指定說明檔的索引。

ShowPopup(Control, String, Point)

顯示 [說明] 快顯視窗 (Pop-Up Window)。

適用於

產品 版本
.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

另請參閱