public void AddF1Event(Control ctl_Param) {
ctl_Param.KeyDown += new KeyEventHandler(ctl_Param_KeyDown);
foreach (Control ctl_Tmp in ctl_Param.Controls) {
if(!(ctl_Tmp is TabPage))
this.AddF1Event(ctl_Tmp);
}
}
private void ctl_Param_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.F1) {
Control o_Tmp = (Control)sender;
// string str_Location = o_Tmp.Name;
// while (o_Tmp != null) {
// str_Location = str_Location + "\n on Control " + o_Tmp.Name;
// if (o_Tmp is Form) {
// MessageBox.Show(str_Location);
// break;
// }
// else {
// o_Tmp = o_Tmp.Parent;
// }
// }
if (o_Tmp is Form)
{
//str_Location = o_Tmp.Name;
}
else
{
while (!(o_Tmp is Form))
{
o_Tmp = o_Tmp.Parent;
}
}
string str_Location = o_Tmp.Text;//这里是获得窗体的text值。
ShowChm(str_Location);
}
}
private void ShowChm(string indexName)
{
// string helpfile = Directory.GetCurrentDirectory() + "\\Chm.chm";//这两个方法都是获得debug目录下的chm文件。
string helpfile = Application.StartupPath + "\\Chm.chm";
HelpNavigator navigator = HelpNavigator.KeywordIndex;//根据CHM文件的索引指到对应的页面。
Help.ShowHelp(this, helpfile,navigator,indexName);
}
在基类的form_load事件下添加AddF1Event(this);