I am using C#.Net. I have textbox which allow only number, decimal and percentage(%) sign. I have the keycode for all number and decimal, but what is the "%" sign's keycode?
How can I check the keydown
event for %?
I am using C#.Net. I have textbox which allow only number, decimal and percentage(%) sign. I have the keycode for all number and decimal, but what is the "%" sign's keycode?
How can I check the keydown
event for %?
Something like this:
private void yourControl_KeyDown(object sender, KeyEventArgs e)
{
if((e.KeyCode == Keys.D5) && e.Shift)
{
// User pressed '%' ...
}
}
or
private void yourControl_KeyDown(object sender, KeyEventArgs e)
{
switch(e.KeyCode)
{
//...
case Keys.D5:
if(e.Shift)
{
// Handle '%'
}
else
{
// Handle '5'
}
break;
// ...
}
}
You want to check that the key being pressed is the 5 key, and that it has been modified by pressing the shift key.
private void control_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue == 53)
{
// %
}
}
Here is a textbox restricting pattern:
private void AmountPaidTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
switch ((byte)e.KeyChar)
{
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 59:
case 46:
case 35:
//This is a valid character
e.Handled = false;
break;
default:
//This is an invalid character
e.Handled = true;
break;
}
}