You need to check to see if e.Shift is true, in addition to just checking the KeyCode property.
Reed Copsey
2010-03-24 01:18:36
You need to check to see if e.Shift is true, in addition to just checking the KeyCode property.
It would be easier to do it this way:
private readonly string VALID_KEYS = "[]~^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; private void txtBox_KeyPress(object sender, KeyPressEventArgs e) { if (VALID_KEYS.IndexOf(char.ToUpper(e.KeyChar)) != -1 || e.KeyChar == (char)8) e.Handled = false; else e.Handled = true; }
Hi,
This might be of some help...
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Shift | Keys.D6:
//Your code
break;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
Thanks, Ram