Well, look at these lines:
int minsEntered = int.Parse(txtMins.Text);
int secsEntered = int.Parse(txtSecs.Text);
What do you expect those to return when the text boxes are blank?
Simply don't call int.Parse
for empty textboxes. For example:
int minsEntered = txtMins.Text == "" ? 0 : int.Parse(txtMins.Text);
// Ditto for seconds
Of course, this will still go bang if you enter something non-numeric. You should probably be using int.TryParse
instead:
int minsEntered;
int.TryParse(txtMins.Text, out minsEntered);
Here I'm ignoring the result of TryParse
, and it will leave minsEntered
as 0 anyway - but if you wanted a different default, you'd use something like:
int minsEntered;
if (!int.TryParse(txtMins.Text, out minsEntered))
{
minsEntered = 5; // Default on parsing failure
}
(Or you can show an error message in that case...)