CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Friday, January 21, 2011

Control HelpButton, HelpRequested, HelpButtonClicked - Instant help for windows Dialog Form components

Instant help for windows dialog components is a great feature and very much known since windows 98. but I saw many many people are not aware it and query on Google to get help, but “help button” for dialogs helps you or your customers to get the help instantly. Every dialog window has help icon if that dialog was coded to enable it. it really helps to know the functionality of the components quickly. For example I was trying to pint a document from acrobat reader and opened printer properties to print the content front and back of the paper.

Windows_Dialog_Help_Button

If you observe there is a help button before close button. To get help on options of “Print on Both Sides” you would need to click on help button first and then click on the area on which you want to see the help. above picture shows help text for the options of “Print on Both Sides”. If you would like to get the help using keyboard you can use F1 key.

Help button can be displayed only if minimize button and maximize button both are not shown unless you want go with custom buttons. below is the way if you want to get Help button for windows forms.

Windows_Form_Help_Demo 
In this sample demo I want to have a checkbox and need to show help when I click on F1 on check box. So I created a form which country check box and help label as show in adjacent picture.

Below is the code for your code bind file.

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial classForm1: Form
  
{
        publicForm1()
        {
            InitializeComponent();
        }

        private void Form1_Load(objectsender, EventArgs e)
        {
            this.Text = "Help Button Demo Form";
            lblHelp.Text = "Press F1 on any component to get Instant Help";

            this.HelpButton = true;
            this.MaximizeBox = false;
            this.MinimizeBox = false;

            chkCountry.Tag = "Check or Uncheck Coutry Check Box";
            chkCountry.HelpRequested += newHelpEventHandler(chkCountry_HelpRequested);
            chkCountry.MouseLeave += newEventHandler(chkCountry_MouseLeave);
        }

        void chkCountry_HelpRequested(objectsender, HelpEventArgs hlpevent)
        {
            ControlrequestingControl = (Control)sender;
            lblHelp.Text = (string)requestingControl.Tag;
            hlpevent.Handled = true;
        }

        void chkCountry_MouseLeave(objectsender, EventArgs e)
        {
            lblHelp.Text = "Press F1 on any component to get Instant Help";
        }
    }
}


In above code  “HelpRequested” is an event will be fired when you click on F1 on Country checkbox. I stored the help information in the checkbox property called “Tag”. You might also maintain a property file to keep help text for each component differently. If you click on F1 when focus is on main form instead on individual component then generally separate help window opens. This can be done using the event “Form.HelpRequested” to open help windows as in below code.

this.HelpRequested += newHelpEventHandler(Form1_HelpRequested);

voidForm1_HelpRequested(objectsender, HelpEventArgs hlpevent)
{
    frmHelp.Show();
}

Post a Comment