I want to open a new form by pressing the F1 key to get something like the picture or can I not do without chm here?

private void Form1_HelpRequested(object sender, HelpEventArgs hlpevent) { Form helpForm = new Form(); helpForm.ShowDialog(); } 

This is not working.

  • and where does this event handler hang it?) - Rostyslav Kuzmovych
  • and indeed, where ... x) - Maria Ivanova
  • Thank you all for the answers, but I'm a chicken and I just did not hang the handler on the form x) - Maria Ivanova

2 answers 2

 private void Form1_HelpRequested(object sender, HelpEventArgs hlpevent) { using (var helpForm = new Form2()) { helpForm.ShowDialog(); } } 

Notice that new Form2() (depending on the name of your form) and not new Form() .

    a source

     protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F1) { MessageBox.Show("You pressed the F1 key"); return true; // indicate that you handled this keystroke } // Call the base class return base.ProcessCmdKey(ref msg, keyData); } 
    • Ctrl + K on the selected code will remove unnecessary indents - Sv__t
    • thanks, I will try to remember - Rostyslav Kuzmovych