C# keypress for the main form

Hi,

i wanted to bind short cut keys (F1-F12) in my application. for example, when user press F1 key, i will load the value to combobox as selecteditem. i have gone thru the web and tutorial but it just did not work. Please give some hints. Thank you.


private void InitializeComponent()
{
.
.
.
this.KeyPress +=new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
}

private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
     if (e.KeyChar.ToString() == Keys.F1.ToString())
     {
                textBoxLogin.Text = "F1";
.
.
      }
}

just have to enable keypreview. :stuck_out_tongue:

this.KeyPreview = true;