/// <summary>
/// 键盘事件:设置文本框能输入数字键与'.'
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtTest_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar)) //可以是数字键与Backspace
{
e.Handled = true;
if (e.KeyChar == '.') //可以输入‘.’
{
e.Handled = txtTest.Text.IndexOf('.') >= 0;
}
}
}