日期:2014-05-17 浏览次数:21144 次
private void text_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !(Char.IsNumber(e.KeyChar) || e.KeyChar == (char)8 || e.KeyChar == '.');
if (!e.Handled) (sender as TextBox).Tag = (sender as TextBox).Text;//记录最后一次正确输入
}
private void text_TextChanged(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch((sender as TextBox).Text, @"^(?!0\d)\d+(\.\d*)?$"))
{
int index = (sender as TextBox).SelectionStart;
(sender as TextBox).Text = (sender as TextBox).Tag as string;
(sender as TextBox).SelectionStart = index;
}
}
private void text_TextChanged(object sender, EventArgs e)
{
if ((sender as TextBox).Text == "")
{
return;
}