@Booney , I agree with the solution of vb2ae, you could try to use textbox.keyup event to get what you want.
I make a sample code and you could have a look.
Code:
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "0";
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back&&textBox1.Text=="")
{
textBox1.Text = "0";
}
if(!int.TryParse(textBox1.Text, out int i))
{
MessageBox.Show("Please enter number and don't contain other character");
textBox1.Text=textBox1.Text.Remove(textBox1.Text.Length - 1,1);
}
}
Result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.