如何将我的帮助文件(CHM)安装在用户安装我的应用程序的文件夹中

时间:2010-12-03 12:41:18

标签: winforms chm

我创建了一个CHM文件,用户可以在点击F1时获得该文件。但我需要的是如何将其安装在用户安装我的应用程序的文件夹中,这样当他点击F1时我必须从他安装的文件夹中读取并显示它。还有我如何在我的应用程序中调用一些东西作为c:\ sample.chm或者我需要从它所在的目录中调用它

2 个答案:

答案 0 :(得分:1)

要安装帮助文件,您必须将其添加到安装项目中,以便将其安装在包含可执行文件的目录中。

一旦您知道帮助文件将在您的可执行文件目录中,您就可以将HelpProvider放到表单上。这会将您的帮助文件连接到F1按钮。您将HelpNamespace设置为帮助文件的路径。要动态计算目录的路径,可以使用System.Reflection.Assembly.GetExecutingAssembly().Location获取可执行文件的路径,然后将其添加到帮助文件的名称中。

     string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
     appPath = System.IO.Path.GetDirectoryName(appPath);
     myHelpProvider.HelpNamespace = System.IO.Path.Combine(appPath, "myHelpFile.chm");

答案 1 :(得分:1)

毕竟我得到了解决方案

  private void frmMain_HelpRequested(object sender, HelpEventArgs hlpevent)
    {
        string dirpath = string.Empty;
        string filename = "ACHWINAPP.chm";
        dirpath=System.Environment.CurrentDirectory;
        string[] files=new string[100];
        do
        {
            if (dirpath ==string.Empty || dirpath == Directory.GetDirectoryRoot(dirpath))
            {
                MessageBox.Show("no helpfile found");
            }
            else
            {
                files=Directory.GetDirectories(dirpath,"ACH");
                if (files.Length>0)
                {
                    //MessageBox.Show(files[0]);
                    string strHlp = string.Empty;
                    strHlp = files[0] + "\\ACHWINAPP.chm";
                    Help.ShowHelp(this, strHlp);
                    break;
                }
                else
                {
                    dirpath = Directory.GetParent(dirpath).ToString();
                }
            }
        } while (true);

    }