Posts Tagged ‘keychar’

How to make TextBox accept only Deecimal Values?

December 9, 2008
How to make textbox to allow decimal values in textbox in c#.net windows forms.

private void txtRate_KeyPress(object sender, KeyPressEventArgs  e)
{
    if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) &&   !(e.KeyChar.Equals('.')))
          e.Handled =true;
}
Udhaya
PiSquare

Customizing TextBox

November 28, 2008

Allowing Only numbers in TextBox

Insert this code in KeyPress event of textBox

private void txtYear_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
e.Handled = true;
}

Allowing Only Letters & White Space in TextBox

private void cmbAuthor_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
e.Handled = true;
}

Setting Maximum Length of TextBox

Select the Text Box and Change the Max Length Propety

Udhaya

PiSquare


Follow

Get every new post delivered to your Inbox.