下面比较啰嗦,只一句即可:
Help.ShowHelp(null,"C:\help.hcm", HelpNavigator.Topic,"index.htm")

方法一: Process.Start()

在没有更多需求的情况下,用这种方法可以打开 chm 文件并定位至文件首页。

using System.Diagnostics;

string filepath = @"C:\helpdoc.chm";
Process.Start(filepath);

方法二: Help.ShowHelp()

如果需要在打开 chm 文件的同时定位到某一特定页面,则可以使用 Help.ShowHelp(),
这个方法原本用于 WinForm 程序中操作帮助文档。

方法有四个重载,详见http://msdn.microsoft.com/en-us/library/system.windows.forms.help.showhelp.aspx

ShowHelp(Control, String) Displays the contents of the Help file at the specified URL.
ShowHelp(Control, String, String) Displays the contents of the Help file found at the specified URL for a specific keyword.
ShowHelp(Control, String, HelpNavigator) Displays the contents of the Help file found at the specified URL for a specific topic.
ShowHelp(Control, String, HelpNavigator, Object) Displays the contents of the Help file located at the URL supplied by the user.

其中 HelpNavigator 用于指定文件打开时显示的内容。HelpNavigator 的具体介绍如下:
http://msdn.microsoft.com/en-us/library/system.windows.forms.helpnavigator.aspx

这里使用了 ShowHelp() 的最后一个重载:

using  System.Windows.Forms;

string filepath = @"C:\helpdoc.chm";
Help.ShowHelp(null, filename, HelpNavigator.Topic, "index.html"); 
//index.html 是打开文件时要显示的页面

url:http://greatverve.cnblogs.com/archive/2012/05/24/csharp-chm.html

用C#实现利用F1打开帮助文件

最近需要做帮助文档,所以在网上查了一下,这里把一些有用的资料摘录一下。

     1. 首先这篇文章是比较详细的一个介绍:

Open Help file on F1 function key press in windows application

This article explains how to open help file on F1 Function key press in windows application.

Almost all applications need Help file. It could be .chm , .PPT, . HTML, .PDF or any other kind of file which you want to open on F1 key press. Lets see how can we do that.

.NET Framework provides F1helpProvider component to handle F1 key press. You can use this component to show help file (.chm, .PPT, .PDF etc.,) to the user. The developer need not have to write even a single line of C# or Vb.Net code to display help file on press of F1 function key from keyboard.

You can find the helpProvider component under Component tab of ToolBox in Visual Studio. Below is the pic which will guide you to find Helpprovider component.

(在windows应用程序中按F1功能键打开帮助文件

本文介绍如何在windows应用程序中按F1功能键打开帮助文件。
几乎所有应用程序都需要帮助文件。它可以是.chm、.PPT、.HTML、.PDF或任何其他类型的文件,您可以按F1键打开这些文件。让我们看看如何做到这一点。
.NET Framework提供F1helpProvider组件来处理F1键按下。您可以使用此组件向用户显示帮助文件(.chm、.PPT、.PDF等)。开发人员无需编写哪怕是一行C#或Vb.Net代码,就可以在按下键盘上的F1功能键时显示帮助文件。
您可以在Visual Studio中的ToolBox的“组件”选项卡下找到helpProvider组件。下面是指导您查找帮助提供者组件的图片。)

Now Just drag helpProvider into your application. Then go to the property of HelpProvider and Set its "HelpNamespace" property to your desired help file path. Below is the picture which will guide you to do that.
(现在只需将helpProvider拖到应用程序中。然后转到HelpProvider的属性,并将其“HelpNamespace”属性设置为所需的帮助文件路径。下面的图片将指导您这样做。)

Once you set the property, then compile and run your sample application.

Now click F1 Button from your keyboard when the focus is on your application and you will see your help file opened.

You can also set the different property of helpProvider componet (Which you have added in the main form) from the MainForm property window, for eg., set the TOC when user clicks on the F1 key. You can also set the property to show window help button etc.,

(设置属性后,编译并运行示例应用程序。

现在,当焦点放在应用程序上时,单击键盘上的F1按钮,您将看到帮助文件已打开。
您还可以从MainForm属性窗口设置helpProvider组件的不同属性(已在主窗体中添加),例如,当用户单击F1键时设置TOC。您还可以将属性设置为显示窗口帮助按钮等。,


Now we will see how to display help topic in a .chm file by keyword on a Button Click

Step 1 -> Click Button1 and display its properties.
Step 2 ->Set the HelpKeywordonHelpProvider1 property to "Your .CHM Topic". 
Step 3 -> Set the HelpNavigatoronHelpProvider1 property to "KeywordIndex".
Step 4 -> Compile and run your application

If you want to set using Code you can do like this

helpProvider1.HelpNamespace =

"C:/helpFile.chm";

HelpNavigator.KeywordIndex); //Set the Keyword

helpProvider1.SetHelpKeyword(Button1,

"Your .CHM Topic"); // Topic in help file.

helpProvider1.SetHelpNavigator(Button1,

Hope this will help all who wants to integrate F1 key press to open help file in windows application.

(希望这将帮助所有想要集成F1键以在windows应用程序中打开帮助文件的人。)

2. 这里主要用到HelpProvider类,它用于提供控件的弹出或联机帮助。

每个 HelpProvider 实例均维护一个对关联控件的引用的集合。若要使帮助文件与 HelpProvider 关联,请设置 HelpNamespace 属性。通过调用 SetHelpNavigator 方法并提供指定控件的 HelpNavigator 值来指定提供的帮助类型。通过调用 SetHelpKeyword 方法为帮助提供关键字或主题。若要打开特定主题的帮助,则应以 topicName.htm 的形式传入关键字。

若要使特定的帮助字符串与控件关联,请使用 SetHelpString 方法。如果用户在控件包含焦点时按下 F1 键,使用此方法与控件关联的字符串将显示在弹出窗口中。

如果尚未设置 HelpNamespace 属性,则必须使用 SetHelpString 方法提供帮助文本。如果同时设置了 HelpNamespace 和帮助字符串,则基于 HelpNamespace 的帮助信息优先。

HelpProvider 在 Help 类上调用方法来提供帮助功能。

HelpProvider控件可以挂起控件,显示帮助主题。
1.SetShowHelp()方法:设置指定控件是否显示帮助信息;
2.HelpNamespace()方法:设置帮助文件;
3.SetHelpKeyword()方法:为帮助文件设置关键字;
4.SetHelpNavigator()方法:设置显示帮助中的元素;
5.SetHelpString()方法:将帮助信息的文本字符串关联到控件上。

TestHelpProvider:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace TestHelpProvider
  9. {
  10. public partial class Form1 : Form
  11. {
  12. public Form1()
  13. {
  14. InitializeComponent();
  15. }
  16. private void Form1_Load(object sender, EventArgs e)
  17. {
  18. //将帮助信息的文本字符串关联到控件上,在相应控件上按下F1键时显示
  19. helpProvider1.SetHelpString(textBox1, "Enter an age that is less than 65.");
  20. helpProvider1.SetHelpString(textBox2, "Enter a 5 digit post code.");
  21. }
  22. }
  23. }

3. 介绍了菜单项显示帮助文档:

The HelpProvider control is used to show how to link to specific keyword in a .chm help file.

private void mnuContentsHelp_Click(object sender, System.EventArgs e) 
{
        // Show the contents of the help file.
        Help.ShowHelp(this, hpAdvancedCHM.HelpNamespace);
    }

    private void mnuIndexHelp_Click(object sender, System.EventArgs e) 
{
        // Show index of the help file.
        Help.ShowHelpIndex(this, hpAdvancedCHM.HelpNamespace);
    }

    private void mnuSearchHelp_Click(object sender, System.EventArgs e) 
{
        // Show the search tab of the help file.
        Help.ShowHelp(this, hpAdvancedCHM.HelpNamespace, HelpNavigator.Find, "");
    }

4. 一个邮件介绍:

If you use F1HelpProvider control. When you press F1 on the active control It will shows a pop up with Text which you have set already. Follow the Steps Below: 

1. Select the F1HelpProvider control from ToolBox and Drag it to your Windows Form. 
2. Set the following code in the Page Load event of your Form. 

helpProvider1.SetHelpString(txtPinCode, "Please Enter Ur city pin Code."); 

In the above code txtPinCode is a TextBox. 
3. Then run your application by pressing F5. 
4. If you have focus on the Text Box Pin Code then press F1. It will shows a Message that you have set likely to be ToolTip.

5.一个最好的例子,看了就明白。

Donwload example project C# 2005 Express from:
http://www.help-info.de/download/CSharp_CHM.zip
The CHM file resides in the DEBUG folder and you have to do following before giving that a try:
to open the CHM file right-click the saved file, click Properties, and then click Unblock.

(他说需要对CHM文件做这样的操作,我试了,可以直接F1打开,你们要是有问题就按照步骤)。

下面是代码:

private void Form1_Load(object sender, EventArgs e)
        {
            // set F1 help topic for this form
            helpProvider1.HelpNamespace = Application.StartupPath + @"\" + sHTMLHelpFileName;
            helpProvider1.SetHelpNavigator(this, HelpNavigator.Topic);
            helpProvider1.SetHelpKeyword(this, @"/Garden/garden.htm");
            helpProvider1.SetHelpNavigator(this.btnStart, HelpNavigator.Topic);
            helpProvider1.SetHelpKeyword(this.btnStart, @"/Garden/flowers.htm");
            helpProvider1.SetHelpNavigator(this.btnExit, HelpNavigator.Topic);
            helpProvider1.SetHelpKeyword(this.btnExit, @"/Garden/tree.htm");
            helpProvider1.SetHelpNavigator(this.chkMain, HelpNavigator.Topic);
            helpProvider1.SetHelpKeyword(this.chkMain, @"/HTMLHelp_Examples/jump_to_anchor.htm#AnchorSample");
       }

Thanking you

我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。

有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。

 
这个是复制一大佬的,防止博客废弃,所以在此备份,侵权联删。
 
所有方法我全部都测试过:
此文档若是有问题的可以及时回来评论反馈,每天看到都会回复。

Winform帮助文档(C#打开chm定位到特定页面)国内最全总结写法。原文文档带翻译的更多相关文章

  1. 史上最全Beyond Compare中文文档.CHM (根据官网整理编辑)

    截图如下:  下载地址: 链接:https://pan.baidu.com/s/1Ml98_biT1leXxGLr9fqI_w 提取码:p8jg

  2. IdentityServer4 中文文档 -7- (简介)贡献

    IdentityServer4 中文文档 -7- (简介)贡献 原文:http://docs.identityserver.io/en/release/intro/contributing.html ...

  3. 一、frp官方中文文档

    frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp, http, https 协议. 目录 frp 的作用 开发状态 架构 使用示例 通过 ssh 访问公司内网机器 通过自定义 ...

  4. FRP 中文文档

    https://github.com/fatedier/frp/blob/master/README_zh.md README | 中文文档 frp 是一个可用于内网穿透的高性能的反向代理应用,支持 ...

  5. IdentityServer4 中文文档 -11- (快速入门)添加基于 OpenID Connect 的用户认证

    IdentityServer4 中文文档 -11- (快速入门)添加基于 OpenID Connect 的用户认证 原文:http://docs.identityserver.io/en/releas ...

  6. IdentityServer4 中文文档 -9- (快速入门)使用客户端凭证保护API

    IdentityServer4 中文文档 -9- (快速入门)使用客户端凭证保护API 原文:http://docs.identityserver.io/en/release/quickstarts/ ...

  7. 教你阅读MSDN英文文档,迅速提升编程能力

    在教大家阅读英文文档之前,首先给大家明确一个概念.C#和.NET的区别? 有一定编程经验的同学应该多多少少知道这方面的概念,但是可能模糊,理解的不一定深刻.我在这里简单给出两者的基本定义: C#:仅仅 ...

  8. Kotlin 中文文档

    Kotlin 中文文档 标签: Kotlinkotlin中文文档 2017-02-14 18:14 4673人阅读 评论(0) 收藏 举报  分类: kotlin 转载地址:http://www.tu ...

  9. java中文文档官方下载

    一直在寻找它,今天无意之间终于发现它了! http://download.oracle.com/technetwork/java/javase/6/docs/zh/api/overview-summa ...

  10. jQuery API中文文档

    jQuery API中文文档 http://www.css88.com/jqapi-1.9/category/events/event-handler-attachment/ jQuery UI AP ...

随机推荐

  1. 跳板攻击之: MSF 添加路由方式渗透内网

    跳板攻击之: MSF 添加路由方式渗透内网 目录 跳板攻击之: MSF 添加路由方式渗透内网 1 Metasploit 跳板攻击: 添加路由方式原理 2 实验环境 2.1 建立 meterpreter ...

  2. 《HelloGitHub》第 83 期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweiha ...

  3. Linux内存占用过高排查过程

    1 查看服务器状态 系统是 CentOS Linux release 7.5.1804 (Core)使用top命令看了下系统的状态 系统的整体负载和cpu并不高,但是内存使用比较高(总8G使用了7.2 ...

  4. Nextcloud的一些错误提示

    Nextcloud的一些错误提示 PHP 内存限制低于建议值 512MB 您可以通过以下步骤增加PHP内存限制: 打开php.ini文件 在终端中输入以下命令打开php.ini文件: bash sud ...

  5. switch-声明和类型模式匹配

    1.声明和类型模式:类型为 T 的声明模式在表达式结果为非 NULL 且满足以下任一条件时与表达式匹配 var numbers = new int[] { 10, 20, 30 }; Console. ...

  6. elasticsearch-8.6.1集群安装部署

    elk官方下载地址:https://www.elastic.co/cn/downloads/ 1.创建普通用户及用户组 groupadd elasticsearch useradd elasticse ...

  7. CodeGym自学笔记08——交互对象

    交互对象 用 Java 语言编写的每个程序都由类和对象组成. 1."Java 程序员就像设计工程师一样,只是他们不制作蓝图,而是编写类.船舶零件是根据蓝图制造的,而对象是基于类创建的.&qu ...

  8. 使用vue+iview创建自己的对话框组件

    通过对别的案例反复研究,终于总结出自己对于使用vue+iview创建组件的步骤: 第一步:编辑新建对话框组件(子组件) <template> <div> <!-- mod ...

  9. 微信带参数的小程序码生成并上传到七牛云(java)

    在大家看正式内容之前请耐心的听我把这段话说完:我冒昧的猜一下,你为了解决问题估计已经看了很多文章了,如果这边文章能给你带来帮助,不胜荣幸,如果有错误也请批评指正,共同进步,我之前在完成这个功能之前,从 ...

  10. leetcode 跳跃游戏系列

    55. 跳跃游戏 能跳一个范围,贪心 class Solution { public: bool canJump(vector<int>& nums) { int m = 0; / ...