Click here to Skip to main content
15,896,444 members
Articles / Desktop Programming / Windows Forms

C# WinForms Application Full Integration with HTMLHelp ( .chm ) - Help Topics, Context Sensitive Help, and Tooltips

Rate me:
Please Sign up or sign in to vote.
4.67/5 (12 votes)
4 May 2011CPOL5 min read 64.3K   2.2K   48  
Use HTMLHelp (.chm) to display help topics, context sensitive help and tooltips in C# Winform application
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using WinHelpLib;


namespace WinHelpTest
{
    public partial class MainForm : Form
    {

        public WinHelpEx.HELP_CTRL_USE GetControlName(Control ctrl, ref string sName)
        {
            if (ctrl == btnHelp)
            {
                sName = "ButtonHelp";
                return WinHelpEx.HELP_CTRL_USE.USE_NO_SUB;
            }

            sName = "";
            return WinHelpEx.HELP_CTRL_USE.USE_SUB;
        }
        public WinHelpEx.HELP_CTRL_USE IsControlUsed(Control ctrl)
        {
            return WinHelpEx.HELP_CTRL_USE.USE_SUB;
        }

        public WinHelpEx.HELP_CTRL_USE IsControlTTUsed(Control ctrl)
        {
            if (ctrl == this)
            {
                return WinHelpEx.HELP_CTRL_USE.USE_SUB;
            }
            return WinHelpEx.HELP_CTRL_USE.USE_SUB;
        }


        Boolean IsCSHelpDlgt(Control ctrl)
        {
            if (ctrl == tvHF || ctrl == cbHC || ctrl == this)
            {
                return false;
            }
            return true;
        }

        public MainForm()
        {
            InitializeComponent();

            try
            {

                Program.s_help.TestITSS(tvHF);

                Program.s_help.AttachForm(null, this, true, IsControlUsed, GetControlName, IsCSHelpDlgt, IsControlTTUsed, GetControlName);

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }

            object[] arr = new[]
            {
                new { Text = "TableOfContents", Data = HelpNavigator.TableOfContents },
                new { Text = "Topic", Data = HelpNavigator.Topic },
                new { Text = "TopicId", Data = HelpNavigator.TopicId },
                new { Text = "Index", Data = HelpNavigator.Index },
                new { Text = "Find", Data = HelpNavigator.Find },
                new { Text = "AssociateIndex", Data = HelpNavigator.AssociateIndex },
                new { Text = "KeywordIndex", Data = HelpNavigator.KeywordIndex }
            };

            cbHC.DisplayMember = "Text";
            cbHC.ValueMember = "Data";
            cbHC.DataSource = arr;

        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            Program.s_help.ShowHelp(this,(HelpNavigator)cbHC.SelectedValue, tbKW.Text);
        }

        private void MainForm_HelpRequested(object sender, HelpEventArgs hlpevent)
        {

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions