I have a C # application where I use Messagebox.Show using the help button, according to the Microsoft example at http://msdn.microsoft.com/en-us/library/szwxe9we.aspx
I add an event to the form, but clicking the help button never triggers the event - pressing F1 on the DOES form. Even the Microsoft example doesn’t almost trigger the event. Below is all the code. Any ideas what I am not doing?
There is another message where someone noticed the same thing.
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;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DialogResult r = AlertMessageWithCustomHelpWindow();
}
private DialogResult AlertMessageWithCustomHelpWindow()
{
this.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.Form1_HelpRequested);
this.Tag = "Message with Help button.";
DialogResult r = MessageBox.Show("Message with Help button.",
"Help Caption", MessageBoxButtons.OK,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
0, true);
this.HelpRequested -= new System.Windows.Forms.HelpEventHandler(this.Form1_HelpRequested);
return r;
}
private void Form1_HelpRequested (System.Object sender, System.Windows.Forms.HelpEventArgs hlpevent)
{
Form helpForm = new Form();
helpForm.StartPosition = FormStartPosition.Manual;
helpForm.Size = new Size(200, 400);
helpForm.DesktopLocation = new Point(this.DesktopBounds.X +
this.Size.Width,
this.DesktopBounds.Top);
helpForm.Text = "Help Form";
Label helpLabel = new Label();
helpForm.Controls.Add(helpLabel);
helpLabel.Dock = DockStyle.Fill;
Control senderControl = sender as Control;
helpLabel.Text = "Help information shown in response to user action on the '" +
(string)senderControl.Tag + "' message.";
this.AddOwnedForm(helpForm);
helpForm.Show();
hlpevent.Handled = true;
}
}
}
source
share