C# Winform TextBox控件多行输入方式

  private void textBox_KeyPress(object sender, KeyPressEventArgs e)

  {

  if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 46)

  e.Handled = true;//小数点得处理

  if(e.KeyChar==46)//小数点

  {

  if(textBox_price.Text.Length<=0)

  {

  e.Handled = true;//小数点不能在第一位

  }

  else

  {

  float f;

  float oldf;

  bool b1 = false, b2 = false;

  b1 = float.TryParse(textBox_price.Text, out oldf);

  b2 = float.TryParse(textBox_price.Text + e.KeyChar.ToString(), out oldf);

  if(b2==false)

  {

  if(b1==true)

  {

  e.Handled = true;

  }

  else

  {

  e.Handled = false;

  }

  }

  }

  }

  }