Monday, April 6, 2009

allow decimal values in textbox in c#.net windows forms.

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;}


---------------------------VB.NET-------------------------------
Dim decexist As Boolean = False
If (CType(sender, TextBox).Text.IndexOf(".") > 0) And e.KeyChar.Equals("."c) Then
decexist = True
End If

If (Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not (e.KeyChar.Equals("."c))) Or decexist Then
e.Handled = True
End If

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates