TextBox accept only numeric value with only one ‘.’ in C#

If we want to enter only numeric character (0 to 9 and point {‘.’}) into textbox field, you can use following code snippt
you need to call textvalidate() function on keypress event of that text box like this:

 
 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            textvalidate(textBox1, e);
        }
 
private void textvalidate(TextBox textbox, KeyPressEventArgs e)
        {
            bool IsNumeric = false;
            string Text = textbox.Text;
            if (e.KeyChar == '\b')
            {
                e.Handled = false;
            }
            else
            {
                if (!char.IsDigit(e.KeyChar))
                {
                    e.Handled = true;
                }
                else
                {
                    e.Handled = false;
                    IsNumeric = true;
                }
                if (!IsNumeric)
                {
                    if (e.KeyChar.ToString() == ".")
                    {
                        if (Text.IndexOf('.') == -1)
                        {
                            e.Handled = false;
                        }
                    }
                }
            }
        }