1 /// <summary> 2 /// txtbox只能输入小数 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void txtzhongxiang_KeyPress(object sender, KeyPressEventArgs e) 7 { 8 if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8) 9 { 10 int i = ((TextBox)sender).Text.IndexOf('.'); 11 if (e.KeyChar == '.' && ((TextBox)sender).Text.IndexOf('.') == -1) 12 { 13 14 e.Handled = false; 15 } 16 else 17 { 18 e.Handled = true; 19 } 20 } 21 else 22 { 23 if (e.KeyChar == (char)13) 24 { 25 button3_Click(sender, e); 26 } 27 else 28 e.Handled = false; 29 } 30 }