Saturday 25 May 2013

C# TextBox Numeric Value with one decimal point


private void txtBasicSal_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)&& e.KeyChar != '.')
            {
                e.Handled = true;
            }

            // only allow one decimal point
            if (e.KeyChar == '.'&& (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }
        }

No comments:

Post a Comment