Wed 21 Jan 2009

Tonight in windows form, using C# language I required to use key combination like we use Ctrl+S to save form, CTRL+F to find etc.

In windows form, its quite easy. Just enable KeyPreview property to true. This property makes the form get the key events before the controls, so you can set the KeyPress event on the form.

Form1.KeyPreview = true;

After that, set the form event for the keypress/key down

this.KeyDown += new KeyEventHandler(this.Form1_KeyDown);

Now shortcut part comes here, follow like this

private void Form1_KeyDown(object sender, KeyEventArgs e)
 if (Control.ModifierKeys == Keys.Control && e.KeyCode == Keys.S)
 else if (Control.ModifierKeys == Keys.Control && e.KeyCode == Keys.F)

Hope it helps some one.


Tags: ,
Comments (1)


5/26/2009 | Zaki  Russia
.KeyPreview = true; //requred thing

Thank you very much!

Add Comment Post comment

   Country flag