Use the. chm help file in C #

Source: Internet
Author: User

When you add the compiled. chm Help file (which can be made with EasyCHM,: http://download.csdn.net/detail/xiaoyaofriend/4501571) to a program written in C #, you need to call the ShowHelp and ShowHelpIndex static methods of the Help class. The following describes the two methods in detail.
(1) ShowHelp method. Displays the content of the Help file. This method has four overload forms. Their syntax forms are as follows.
Syntax 1:
Public static void ShowHelp (Control parent, string url)
The parameters are described as follows.
Parent: Specifies the parent-level Control in the Help dialog box.
Url: the path and name of the Help file.
Returned value: displays the Help file content at the specified URL.
Syntax 2:
Public static void ShowHelp (Control parent, string url, HelpNavigatornavigator)
The parameters are described as follows.
Parent: Specifies the parent-level Control in the Help dialog box.
Url: the path and name of the Help file.
Navigator: One of the HelpNavigator values. HelpNavigator Value
Syntax 3:
Public static void ShowHelp (Controlparent, string url, string keyword)
The parameters are described as follows.
Parent: Specifies the parent-level Control in the Help dialog box.
Url: the path and name of the Help file.
Keyword: the keyword for displaying help information.
Returned value: displays the Help File Content for specific keywords found at the specified URL.
Syntax 4:
Public static void ShowHelp (Control parent, string url, HelpNavigatorcommand, Object parameter)
The parameters are described as follows.
Parent: Specifies the parent-level Control in the Help dialog box.
Url: the path and name of the Help file.
Command: One of the HelpNavigator values. The HelpNavigator values and descriptions are shown in table 4.
Parameter: any type of Parameter.
Returned value: displays the Help file content at the URL provided by the user.
(2) ShowHelpIndex method. Displays the index of the specified help file.
Syntax:
Public static void ShowHelpIndex (Control parent, string url)
Example
Call the. chm help file in a Windows Application
In this example, when the program runs, click the help button to call the. chm help file in the program.
Main program code.
Private void bnthelp_Click (object sender, EventArgs e)
{
String helpfile = Application. startupPath. substring (0, Application. startupPath. substring (0, Application. startup Path. lastIndexOf ("\\")). lastIndexOf ("\\"));
Helpfile + = @ "\ help \ mrHelp. chm ";
Help. ShowHelp (this, helpfile );
Help. ShowHelpIndex (this, helpfile); // displays the index of the specified Help.
}
The complete program code is as follows:
★★★★★Form1.cs form code file complete program code★★★★★
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Namespace _ 5_02
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
}
Private void bnthelp_Click (object sender, EventArgs e)
{
String helpfile = Application. startupPath. substring (0, Application. startupPath. substring (0, Application. startupPath. lastIndexOf ("\\")). lastIndexOf ("\\"));
Helpfile + = @ "\ help \ mrHelp. chm ";
Help. ShowHelp (this, helpfile );
Help. ShowHelpIndex (this, helpfile); // displays the index of the specified Help.
}
Private void button#click (object sender, EventArgs e)
{
}
}
}
★★★★★Form1.Designer. cs form code file complete program code★★★★★
Namespace _ 5_02
{
Partial class Form1
{
/// <Summary>
/// Required designer variables.
/// </Summary>
Private System. ComponentModel. IContainer components = null;
/// <Summary>
/// Clear all resources in use.
/// </Summary>
/// <Param name = "disposing"> If the managed resource should be released, the value is true; otherwise, the value is false. </Param>
Protected override void Dispose (bool disposing)
{
If (disposing & (components! = Null ))
{
Components. Dispose ();
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not
/// Use the code editor to modify the content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. bnthelp = new System. Windows. Forms. Button ();

This. helpProvider1 = new System. Windows. Forms. HelpProvider ();
This. SuspendLayout ();
//
// Bnthelp
//
This. bnthelp. Location = new System. Drawing. Point (91, 34 );
This. bnthelp. Name = "bnthelp ";
This. bnthelp. Size = new System. Drawing. Size (70, 23 );
This. bnthelp. TabIndex = 0;
This. bnthelp. Text = "help ";
This. bnthelp. UseVisualStyleBackColor = true;
This. bnthelp. Click + = new System. EventHandler (this. bnthelp_Click );
//
// Form1
//
This. AutoScaleDimensions = new System. Drawing. SizeF (6F, 12F );
This. AutoScaleMode = System. Windows. Forms. AutoScaleMode. Font;
This. ClientSize = new System. Drawing. Size (292, 99 );
This. Controls. Add (this. bnthelp );
This. Name = "Form1 ";
This. Text = "Help reference ";
This. Load + = new System. EventHandler (this. form#load );
This. ResumeLayout (false );
}
# Endregion
Private System. Windows. Forms. Button bnthelp;
Private System. Windows. Forms. HelpProvider helpProvider1;
}
}
★★★★★Complete Program code of the Program. cs main Program file★★★★★
Using System;
Using System. Collections. Generic;
Using System. Windows. Forms;
Namespace _ 5_02
{
Static class Program
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
Application. EnableVisualStyles ();
Application. SetCompatibleTextRenderingDefault (false );
Application. Run (new Form1 ());
}
}
}

(3) call it through Process.

For example:

System. Diagnostics. Process p = new System. Diagnostics. Process ();

P. StartInfo. FileName = "helpfile. chm ";

P. Start ();

There seems to be no better way to view chm on the Web.

(4) HelpProvider Control

The HelpProvider control can suspend controls to display help topics.
SetShowHelp () method: sets whether the specified control displays help information;
HelpNamespace () method: sets the Help file;
SetHelpKeyword () method: Set a keyword for the help file;
SetHelpNavigator () method: sets the elements in the display help;
SetHelpString () method: Associate the text string of the help information to the control.

The procedure is as follows:

The A Help button cannot coexist with the maximize and minimize buttons.

Set form attributes:

MaximizeBox = false;
MinimizeBox = false;

HelpButton = true;


B. Add the control helpProvider.

This control can contain a Help file, chm


C. Associate the helpProvider control with the form.

Set form attributes: (the same applies to other controls)

HelpKeyword on helpProvider index corresponds to the index in the Help File

HelpNavigator on helpP


D. Load the Help file to the control helpProvider.

Public Form1 ()
{
InitializeComponent ();
String strpath = Application. startupPath. substring (0, Application. startupPath. substring (0, Application. startupPath. lastIndexOf ("\\")). lastIndexOf ("\\"));
Strpath + = @ "\ mrHelp. chm ";
HelpProvider1.HelpNamespace = strpath;
}

E implementation click? Help button to implement F1 Functions

In the Click Event of the Help button

Private void form=helpbuttonclicked (object sender, CancelEventArgs e)
{

SendKeys. Send ("{F1 }");
// SendKeys. SendWait ("{F1 }");
}

Code implementation:
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)
{
// Associate the text string of the help information to the control and display it when the F1 key is pressed on the control.
HelpProvider1.SetHelpString (textBox1, "Enter an age that is less than 65 .");
HelpProvider1.SetHelpString (textBox2, "Enter a 5 digit post code .");
}
}
}

Author: xiaoyaofriend

Related Article

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.