Can the Help.ShowHelp API be modified to simply invoke the CHM file?

98 Views Asked by At

This is my primary way for displaying help topics from within my WinForm button click handlers:

  • Handler:
private void buttonHelp_Click(object sender, EventArgs e)
{
    CutTools.DisplayHelpTopic(this, "create-new-viewport.htm");
}
  • Base method:
public static void DisplayHelpTopic(Control parent, string topic)
{
    try
    {
        // Use an empty form as the parent so that the help file will not block the CAD software
        Form mHelpParent = new Form();

        // Use location of this DLL file
        System.Reflection.Module mod = parent.GetType().Module;
        string path = Path.GetDirectoryName(mod.FullyQualifiedName);

        Help.ShowHelp(mHelpParent,
            Path.Combine(path, "cut-tools-help.chm"), HelpNavigator.Topic, topic);
    }
    catch (System.Exception ex)
    {
        _AcAp.Application.ShowAlertDialog(
                            string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
    }
}

The forms are displaid inside AutoCAD, BricsCAD or ZWCAD. The about is fine and great. But if I want to simply display the CHM file itself (so no actual form is available) I have to do this:

[CommandMethod("TS_DisplayHelp")]
public void TS_DisplayHelp()
{
    // Use location of this DLL file
    System.Reflection.Module mod = GetType().Module;
    System.Diagnostics.Process.Start(
        Path.Combine(Path.GetDirectoryName(mod.FullyQualifiedName), "cut-tools-help.chm"));
}

It works but has one drawback. It spawns a new instance of the help and does not use the same instance.

For example:

  • You start one of the other commands and show the help via button click. You cancel.
  • You start a different command and show the help via button click. Help.ShowHelp uses same instance.
  • You can command and start help via TS_DISPLAYHELP and it starts new instance.

Given the context of TS_DISPLAYHELP I can't work out how to directly use Help.ShowHelp as I can in my button click handlers.

1

There are 1 best solutions below

0
Andrew Truckle On BEST ANSWER

At the moment I have managed to get around this issue by duplicating the DisplayHelpTopic code directly in the command TS_DISPLAYHELP method:

[CommandMethod("TS_DisplayHelp")]
public void TS_DisplayHelp()
{
    try
    {
        // Use an empty form as the parent so that the help file will not block the CAD software
        Form mHelpParent = new Form();

        // Use location of this DLL file
        System.Reflection.Module mod = GetType().Module;
        string path = Path.GetDirectoryName(mod.FullyQualifiedName);

        Help.ShowHelp(mHelpParent,
            Path.Combine(path, "cut-tools-help.chm"), HelpNavigator.Topic, "command-index.htm");
    }
    catch (System.Exception ex)
    {
        _AcAp.Application.ShowAlertDialog(
                            string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
    }
}

I know that my default topic is "command-index.htm".


I am happy with the above resolution.