I'm using WinForms and I'm struggling trying to make all the TextBoxes
from a GroupBox
to accept only digits as user input. Is there a way to raise the KeyPress event for all the TextBoxes
in a GroupBox
? Something like this maybe:
private void groupBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)
{
e.Handled = true;
}
}
I'm quite new at this, so please bear with me. Any help would be greatly appreciated.