Compiled HTML Help file shows “This program cannot display…”, when pressing F1 on the debugged application

点点圈 提交于 2019-12-25 18:46:47

问题


I have this problem on my compiled html help file, which runs on Microsoft Visual Studio 2010.

Note: I don't have enough reputation points to post images. Please bear with my problem.

The name of the compiled html help file is GeneralHelp.chm. In order to make it appear, there are two ways:

  1. Clicking the "General" from "Help" Tab.
  2. Pressing F1 Key when the main form is only active.

I don't modify the default values of the properties, but here are the c# codes for the activation:

private void generalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Help.ShowHelp(this, Application.StartupPath + @"\GeneralHelp.chm");
        }

private void mdiMain_Load(object sender, EventArgs e)
            {
                helpProviderGeneral.HelpNamespace = Application.StartupPath + @"\GeneralHelp.chm";
            }

The first way is working properly, but the second way (pressing the F1 Key when the main form is only active) is not. It has a message display "This program cannot display the webpage". I tried reconstructing the .chm file, but it still happens.

Furthermore, I found out it becomes normal when I've clicked the other links first, then clicking the page that I would want to see in the navigation pane. My other .chm files doesn't work in this way. I also saved it in the proper folders: Debug and Release. Also, the spelling and case of GeneralHelp.chm is correct. Lastly, when I tried opening the GeneralHelp.chm, outside from MS Visual Studio 2010, it's just normal.

If you need further info, please comment and I'll answer. I just really want to know how this problem be solved. Thanks for the time reading this, I'm looking forward in granting me a solution.


回答1:


You can imagine helpProvider1.HelpNamespace as a link to the .chm help file. Thus, no help topic on this way can be called. You must have knowledge of the internal structure of the CHM help file as a root node. Think of a structured web page ("homepage") on a web Server with (sub)directories and HTML Topics e.g. @"/Garden/flowers.htm".

As mentioned earlier by other comments (see above) make sure that the .chm file got copied to your EXE project's bin\Debug directory.

In the code example, I've set constants at the beginning. The examples of the CHM Help files depend on how they were compiled by the technical writer e.g. with HTMLHelp Workshop or other Help Authoring tools and are intended here to represent the possibilities.

Please note the inline comments: // set F1 help topic for this form ... // and set F1 help topic for some controls of this form (two lines per control).

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



来源:https://stackoverflow.com/questions/25831341/compiled-html-help-file-shows-this-program-cannot-display-when-pressing-f1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!