首页 > 编程语言 >Winform帮助文档(C#打开chm定位到特定页面)

Winform帮助文档(C#打开chm定位到特定页面)

时间:2023-01-03 16:00:12浏览次数:59  
标签:F1 help 控件 C# chm helpProvider1 file Help Winform

下面比较啰嗦,只一句即可:
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

Public methodStatic member ShowHelp(Control, String) Displays the contents of the Help file at the specified URL.
Public            methodStatic member ShowHelp(Control, String, String) Displays the contents of the Help file found at the specified URL for a specific keyword.
Public methodStatic member ShowHelp(Control, String, HelpNavigator) Displays the contents of the Help file found at the specified URL for a specific topic.
Public methodStatic member 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.

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.

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.,

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.

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.   
  9. namespace TestHelpProvider   
  10. {   
  11.     public partial class Form1 : Form   
  12.      {   
  13.         public Form1()   
  14.          {   
  15.              InitializeComponent();   
  16.          }   
  17.   
  18.         private void Form1_Load(object sender, EventArgs e)   
  19.          {   
  20.             //将帮助信息的文本字符串关联到控件上,在相应控件上按下F1键时显示   
  21.              helpProvider1.SetHelpString(textBox1, "Enter an age that is less than 65.");   
  22.              helpProvider1.SetHelpString(textBox2, "Enter a 5 digit post code.");   
  23.          }   
  24.      }   
  25. }  

 

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

 

 

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

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

  这个是复制一大佬的,防止博客废弃,所以在此备份,侵权联删。

标签:F1,help,控件,C#,chm,helpProvider1,file,Help,Winform
From: https://www.cnblogs.com/CS-ComputerScience/p/17022510.html

相关文章

  • ASR6601:国产化lora SOC芯片兼容SX1262/SX1268
    ASR6601为目前首颗国产化支持LoRaWAN低功耗广域网无线通信SoC芯片。ASR6601在单芯片上集成了通用微控制器和射频单元(SX1262),包括射频收发器,调制解调器和48MHz主频、Arm......
  • java 类型转换器Convert
    /***类型转换器**@authorruoyi*/publicclassConvert{/***转换为字符串<br>*如果给定的值为null,或者转换失败,返回默认值<br>*转......
  • scp port 22: Connection refused
    问题原因:发现是没有安装ssh服务端,没有服务在22号端口接收文件。ubuntu下安装ssh客户端,服务端1.安装ssh服务端sudoapt-getinstallopenssh-server;2.确认sshserver是否启动......
  • TCP
    引言TCP提供面向连接的、可靠的字节流服务在一个TCP连接中,仅有两方进行彼此通信TCP通过下列方式提供可靠性应用数据被分割成TCP认为最适合发送的数据块。这和UDP不同......
  • java实现excel导入导出
    <!--io常用工具类--><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.11.0</version></dependency><!--e......
  • 1055. Combinations -- ACM RU
    1055.Combinationshttps://acm.timus.ru/problem.aspx?space=1&num=1055 思路对于组合数C(M,N)不能使用公式计算最终值,然后再根据最终值,分解质因数,统计质因数个数;......
  • osgQt使用(osgQOpenGL版本)OSG3.6.5 VS2019 Qt5.15.2 CMAKE3.24
     Qt5.15.2新建QWidget工程QT新建的去qmake工程的.pro文件设置QT+=coreguigreaterThan(QT_MAJOR_VERSION,4):QT+=widgetsCONFIG+=c++17#Youcan......
  • vue+Echarts动态数据已经赋值,但是无法渲染页面的问题
    vue+Echarts动态数据已经赋值,但是无法渲染页面的问题正常的给个div的大小<div><divid="echartss":style="{width:'100%',height:'600px'}"></div></div>......
  • java 反射工具类ReflectUtils
    /***反射工具类.提供调用getter/setter方法,访问私有变量,调用私有方法,获取泛型类型Class,被AOP过的真实类等工具函数.**@authorruoyi*/@SuppressWarni......
  • React 小案例 订单列表评价
    最终效果图:1.功能:各功能组件的组合和渲染   2.点击评价按钮评论组件出现,可输入文字和打分,点击取消按钮关闭评论3.点击提交按钮显示已评价 结构:1.在src下创建components......