Control HelpButton, HelpRequested, HelpButtonClicked - Instant help for windows Dialog Form components
Posted
on Microsoft .NET Support Team
See other posts from Microsoft .NET Support Team
Published on Fri, 21 Jan 2011 10:34:00 +0000
Indexed on
2011/01/28
23:34 UTC
Read the original article
Hit count: 221
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.
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();
}
© Microsoft .NET Support Team or respective owner