Below is the code that I am trying to limit the use of letters in the text box, except for the comma, but it happens that the comma can be typed a hundred times, I would like the comma to be used only once. How is it correct?
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == ',')
{
return;
}
else
{
e.Handled = e.KeyChar != (char)Keys.Back;
}
}