The KeyPress event is only triggered for ASCII characters (letters, digits, punctuations, ...).
To trap the CapsLock key, you have to use the KeyDown (or KeyUp) event. You will then need to replace the KeyChar property with KeyCode.
>I have the following code:
>
>private void MainForm_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
>{
> if ((int)e.KeyChar == (int)Keys.CapsLock){MessageBox.Show("Caps Lock On");}
>}
>
>And the KeyPreview is set to True.
>However, when I press CapsLock key this does not fire. It does fire if press a letter key.
>Why?
>
>TIA
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com