You can do a regex check first to avoid some errors, and it's regex, so it matches or it doesn't, no error unless text field is blank or expression is bad.
Of course, my code might not be the solution you are looking for, but it's a step. You can change the event to whatever you like.
Code:
namespace CodeGuru
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonCheck_Click(object sender, EventArgs e)
{
Regex check = new Regex("[0-9]+");
String text = textBox1.Text;
if (text.Length > 0)
{
Match match = check.Match(text);
Int32 guess = Int32.Parse(match.Value);
MessageBox.Show(guess.ToString());
}
}
}
}
:)