/* *设置textBox只能输入数字(正数,负数,小数) *使用了TextBox的KeyPress事件*/ private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { //允许输入数字、小数点、删除键和负号 if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)(.) && e.KeyChar != (char)(-)) { MessageBox.Show("请输入正确的数字"); this.textBox1.Text = ""; e.Handled = true; } if (e.KeyChar == (char)(-)) { if (textBox1.Text != "") { MessageBox.Show("请输入正确的数字"); this.textBox1.Text = ""; e.Handled = true; } } /*小数点只能输入一次*/ if (e.KeyChar == (char)(.) && ((TextBox)sender).Text.IndexOf(.) != -1) { MessageBox.Show(&
700字范文,内容丰富有趣,生活中的好帮手!