0

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

4

2 回答 2

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");
于 2010-12-03T14:42:16.130 回答
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);

    }
于 2010-12-08T15:13:19.070 回答