C# TEXTBOX中 只允许输入数字和一个小数点

        private void txtPrice_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == '.' || e.KeyChar == ''))
            {
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar == '.')
                {
                    string str = txtPrice.Text;
                    int num = str.IndexOf('.');
                    if (num != -1)
                    {
                        e.Handled = true;
                    }
                }
            }
        }
 

private void txtPassNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(char.IsNumber(e.KeyChar)||(e.KeyChar >= 'a' && e.KeyChar <= 'z')||(e.KeyChar >= 'A' && e.KeyChar <= 'Z')|| e.KeyChar == (Char)Keys.Back))
                e.Handled = true;
        }