簡體   English   中英

在C#中打開CHM(幫助文件)

[英]Open CHM (help file) in C#

我正在嘗試在C#中打開幫助文件(chm擴展名)。

File.Open(@"//help.chm",FileMode.Open, FileAccess.Read, FileShare.Read);

FileStream fileStream = new FileStream(@"c:\help.chm", FileMode.Open);

不起作用:(

您可以使用 -

System.Windows.Forms.Help.ShowHelp(Control, String)

因此,假設您處於表單/控件中

Help.ShowHelp(this, "file://c:\\helpfiles\\help.chm");

ShowHelp方法還提供重載,以轉到位於已編譯HTML幫助文件內的特定主題和幫助頁面。

在MSDN上閱讀System.Windows.Forms.Help.ShowHelp

反編譯CHM文件

就像在命令提示符下執行以下命令一樣容易。

hh.exe -decompile <target-folder-for-decompiled-content> <source-chm-file>

例如:

hh.exe -decompile C:\foo\helpchmextracted help.chm

執行完上述命令后,您應該在C:\\foo\\helpchmextracted文件夾中找到反編譯的內容。

        string helpFileName = @"c:\help.chm";
        if (System.IO.File.Exists(helpFileName))
        {
            Help.ShowHelp(this, helpFileName );                
        }

如果這不起作用,請嘗試

        if (System.IO.File.Exists(helpFileName))
        {
            System.Diagnostics.Process.Start(helpFileName);              
        }

根據請求將我的評論添加到答案中:

似乎第一個語句中的文件名不正確,但是第二個語句應該起作用,除非該文件被鎖定,不存在或者您沒有訪問該文件的權限。 如果要ShellExecute該文件,則應使用System.Diagnostics.Process類,但是如果要提取CHM的內容(由於已對其進行編譯和格式化),則不能像純文本文件一樣讀取它。 看一下這些鏈接:

使用C#反編譯CHM(幫助)文件

CHM幫助文件提取器

 Help.ShowHelp(this, AppDomain.CurrentDomain.BaseDirectory+"\\test.chm", HelpNavigator.Topic, "Welcome.htm");

歡迎是chm文件中歡迎年齡的ID

System.Diagnostics.Process.Start(@"c:\\help.chm");

好吧,第二行應該沒問題,如果文件不存在,它將引發異常。 需要更具體地說明“無效”的含義

簡單做到這一點

Help.ShowHelp(ParentForm,“ chmFile.chm”,“ link.htm”);

暫無
暫無

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

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