Modify your function like below...
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == '.' && !textBox2.Text.Contains(".") || e.KeyChar == '\b')
{
if (textBox2.Text.Contains("."))
{
string[] txt = textBox2.Text.Split('.');
if (txt[1].Length > 1)
{
if (e.KeyChar >= '0' && e.KeyChar <= '9')
{
e.Handled = true;
}
}
}
else
{
e.Handled = false;
}
}
else
{
e.Handled = true;
}
}
Let me know if it works or not...