Hello Code Project Member..
I have a some code to disable some character in textbox control using keypress event with this code :
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (checkBox1.Checked == true)
{
string asciiCode = Convert.ToString(e.KeyChar);
if ((asciiCode == "a" || ((e.KeyChar == '\b'))))
{
}
else
{
e.Handled = true;
}
}
else
{
}
}
and when i am checked checkbox1 control, my desire success to make my textbox1 control can have one input there is only 'a' char. but my problem is come when my goal is to make my textbox1 control can have double input there is only 'a' and 'b'.
when i checked checkbox1 & checkbox2 , my textbox1 control can't get my desire char..
this is the code..
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (checkBox1.Checked == true)
{
string asciiCode = Convert.ToString(e.KeyChar);
if ((asciiCode == "a" || ((e.KeyChar == '\b'))))
{
}
else
{
e.Handled = true;
}
}
else
{
}
if (checkBox2.Checked == true)
{
string asciiCode = Convert.ToString(e.KeyChar);
if ((asciiCode == "b" || ((e.KeyChar == '\b'))))
{
}
else
{
e.Handled = true;
}
}
else
{
}
}
so how to make my textbox1 control only can get 'a' & 'b' char when iam checked checkbox1 & checkbox2 control?