Using C # Implementation to open the Help file with F1

Source: Internet
Author: User

Recently I need to do a help document, so I looked it up on the Internet, and here I extract some useful information.

1. First of all, this article is a more detailed introduction:

Open Help file on F1 function key Press in Windows application

This article explains the how to open Help file on the 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 the file which you want to open on F1 Key press. Lets can we do that.

The. 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 the press of F1 function Key from keyboard.

You can find the HelpProvider component under Component tab to ToolBox in Visual Studio. Below is the pic which would guide you-find helpprovider component.


Now Just drag HelpProvider into your application. Then go to the ' HelpProvider ' and Set its 'helpnamespace ' to your desired Help file path. Below is the "picture which'll guide you.


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

Now click F1 Button from your keyboard then the focus are on your application and you'll be in your help file opened.

can also set the different property of HelpProvider Componet (Which, have added in the main form) from the Mainfor M property window, for eg., set the TOC when user clicks on the F1 key. can also set the property to show Windows Help button etc.,

Now we'll-I -topic in a. chm file by keyword on a Button Click

Step 1-> Click Button1 and display its properties.
Step 2->set the " HelpKeywordonHelpProvider1 " 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 for you can does 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 would help the Who wants to the integrate F1 key Press to the open Help file in Windows application.

2. The main use here is the HelpProvider class, which is used to provide pop-up or online help for controls.

Each HelpProvider instance maintains a collection of references to the associated control. To associate the Help file with the HelpProvider , set the HelpNamespace property. Specifies the type of help provided by calling the SetHelpNavigator method and providing the HelpNavigator value of the specified control. Provide a keyword or topic for help by calling the SetHelpKeyword method. To open Help for a specific topic, you should pass in the keyword in topicname.htm form.

To associate a specific help string with a control, use the Sethelpstring method. If the user presses the F1 key when the control contains the focus, the string associated with the control using this method is displayed in the pop-up window.

If you have not set the HelpNamespace property, you must use the sethelpstring method to provide help text. If both the helpnamespace and help strings are set, the Help information based on HelpNamespace is preferred.

HelpProvider calls methods on the Help class to provide assistance.

The HelpProvider control can suspend controls to display Help topics.
1.SetShowHelp () Method: Sets whether the specified control displays help information;
2.HelpNamespace () Method: Set up Help file;
3.SetHelpKeyword () Method: Set keywords for help files;
4.SetHelpNavigator () Method: Sets the element to display help;
5.SetHelpString () Method: Associates the text string of the Help information to the control.


testhelpprovider:using system;    using system.collections.generic;    using system.componentmodel;    using system.data;    using system.drawing;    using system.text;    using system.windows.forms;       namespace testhelpprovider    {       public  partial class form1 : form        {            public form1 ()             {                InitializeComponent ();            }                private void form1_load (object sender, eventargs e)              {                //the text string of the Help information to the control, and F1 on the corresponding control when the key is pressed                 helpprovider1.sethelpstring (textbox1,  "enter an age that is  Less than 65. ");                 Helpprovider1.sethelpstring (textbox2,  "Enter a 5 digit post code.");           &nbsp}        }    }  

3. The menu item display Help document is described:

The HelpProvider control isn't 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's the Help file.
Help.ShowHelp (this, hpadvancedchm.helpnamespace);
}

private void Mnuindexhelp_click (object sender, System.EventArgs e)
{
Show index to the help file.
Help.showhelpindex (this, hpadvancedchm.helpnamespace);
}

private void Mnusearchhelp_click (object sender, System.EventArgs e)
{
Show the Search tab to the Help file.
Help.ShowHelp (This, hpadvancedchm.helpnamespace, Helpnavigator.find, "");
}

4. An Email introduction:

If use F1helpprovider control. When your press F1 on the active control It'll shows a pop up with Text which for you have set already. Follow the Steps Below:

1. Select the F1helpprovider control-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 your city pin Code.");

In the above code Txtpincode is a TextBox.
3. Then run your application by pressing F5.
4. If you are have focus on the Text Box Pin Code then press F1. It'll shows a message this you have set likely to be ToolTip.


5. One of the best examples, you can see it.

donwload Example Project C # Express from:
Http://www.help-info.de/download/CSharp_CHM.zip
The CHM file resides in the DEBUG folder and your have to does following before giving that a try:
To open the CHM file right-click the saved file, click Properties, and then click Unblock.

(He said that you need to do this to the CHM file, I tried, can directly F1 open, if you have a problem, follow the steps).

Here's the code:

private void Form1_Load (object sender, EventArgs e)
{
Set F1 Help topic to 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.