您可以将 helpProvider1.HelpNamespace 想象为 .chm 帮助文件的链接。因此,无法调用这种方式的帮助主题。作为根节点,您必须了解 CHM 帮助文件的内部结构。考虑一个带有(子)目录和 HTML 主题的 Web 服务器上的结构化网页(“主页”),例如@"/Garden/flowers.htm"。
正如其他 cmets 前面提到的(见上文),请确保将 .chm 文件复制到您的 EXE 项目的 bin\Debug 目录中。
在代码示例中,我在开头设置了常量。 CHM 帮助文件的示例取决于技术作者如何编译它们,例如与 HTMLHelp Workshop 或其他帮助创作工具一起使用,并在此处代表可能性。
请注意内联 cmets: // 为此表单设置 F1 帮助主题 ... // 并为该表单的某些控件设置 F1 帮助主题(每个控件两行)。
namespace C_Sharp_CHM
{
/// <summary>
/// Using C# und CHM files.
/// </summary>
public partial class frmMain : Form
{
private const string sHTMLHelpFileName_ShowSingleHelpWindow = @"\help\CHM-example_ShowSingleHelpWindow.chm";
private const string sHTMLHelpFileName_ShowWithNavigationPane = @"\help\CHM-example_ShowWithNavigationPane.chm";
private const string sHTMLHelpFileName_ShowWithoutAutoSync = @"\help\CHM-example.chm";
public frmMain()
{
InitializeComponent();
}
...
private void frmMain_Load(object sender, EventArgs e)
{
// example: System.Diagnostics.Process.Start(Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync);
webBrowser1.Navigate(new Uri(GetChmUrl(Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync, "Garden/garden.htm")));
if ((chkShowHelpWithNavigationPane.Checked == true))
{
helpProvider1.HelpNamespace = Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync;
}
else
{
helpProvider1.HelpNamespace = Application.StartupPath + sHTMLHelpFileName_ShowSingleHelpWindow;
}
// set F1 help topic for this form
helpProvider1.SetHelpNavigator(this, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this, @"index.htm");
// and set F1 help topic for some controls of this form (two lines per control)
helpProvider1.SetHelpNavigator(this.btnPopulate, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnPopulate, @"/Garden/flowers.htm");
helpProvider1.SetHelpNavigator(this.btnExit, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnExit, @"/Garden/tree.htm");
helpProvider1.SetHelpNavigator(this.chkShowHelpWithNavigationPane, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.chkShowHelpWithNavigationPane, @"/HTMLHelp_Examples/jump_to_anchor.htm#AnchorSample");
helpProvider1.SetHelpNavigator(this.btnOpenHelpShowTopic, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnOpenHelpShowTopic, @"/HTMLHelp_Examples/image_and_text.htm");
}
private void btnOpenHelpShowTopic_Click(object sender, EventArgs e)
{
Help.ShowHelp(this.btnOpenHelpShowTopic, helpProvider1.HelpNamespace, HelpNavigator.Topic, @"/HTMLHelp_Examples/image_and_text.htm");
}