簡體   English   中英

如何在C#Winforms應用程序中顯示chm文件

[英]How to display chm file in c# winforms application

我已將.chm文件添加到我的應用程序根目錄。 當我使用以下代碼獲取文件時,它是指bin / release / somehting.chm的路徑

System.Windows.Forms.Help.ShowHelp(this, Application.StartupPath+"\\"+"somehting.chm");

我想獲取相對於應用程序安裝位置的路徑。 請幫忙。

部署應用程序后,不會加載添加到根目錄中的chm文件。 在Visual Studio中調試時甚至沒有加載,也沒有給出任何錯誤。

在此處輸入圖片說明

你需要 :

String exeDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

因此:

String HelpFilepath = "file://" + Path.Combine(exeDirectory , "somehting.chm");
Help.ShowHelp(this, path);

正如我所看到的,從您的問題中調用Help.ShowHelp的第一個代碼片段還不錯。 有時我使用下面的相關代碼。 可能有許多解決方案...請注意,打字錯誤(例如somehting.chm)會干擾代碼段。

private const string sHTMLHelpFileName = "CHM-example.chm";
...

private void button1_Click(object sender, EventArgs e) {
  System.Windows.Forms.Help.ShowHelp(this, Application.StartupPath + @"\" + sHTMLHelpFileName);
  }

因此,請打開Visual Studio-解決方案資源管理器並檢查CHM文件的屬性。 轉到下面快照中顯示的下拉框,然后設置“始終復制”(此處僅德語)。 Debug模式下啟動項目,然后檢查bin / debug輸出文件夾。 Release模式和輸出文件夾執行相同的操作。 CHM應該駐留在這里,希望您的CHM通話成功。

在此處輸入圖片說明

類似主題的答案是:

// get full path to your startup EXE
string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;

// get directory of your EXE file
string exeDir = Path.GetDirectoryName(exeFile);

// and open Help
System.Windows.Forms.Help.ShowHelp(this, exeDir+"\\"+"somehting.chm");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM