SHARE
TWEET

input only float numbers in TextBox

tolikpunkoff Sep 13th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void txt_KeyPress(object sender, KeyPressEventArgs e)
  2. {
  3.     //ввод только цифр с одной точкой (запятой)
  4.     if ((e.KeyChar == '.') || (e.KeyChar == ','))
  5.     {
  6.         TextBox txt = (TextBox)sender;
  7.         if (txt.Text.Contains(".") || txt.Text.Contains(","))
  8.         {
  9.             e.Handled = true;
  10.         }
  11.         return;
  12.     }
  13.  
  14.     if (!(Char.IsDigit(e.KeyChar)))
  15.     {
  16.         if ((e.KeyChar != (char)Keys.Back))
  17.         {
  18.             e.Handled = true;
  19.         }
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top