You want to prevent that the user enters a decimal-separator? So he is allowed to use integers only? Then don't try to parse to double
but to int
:
if (!int.TryParse(txtDays.Text.Trim(), out days))
{
MessageBox.Show("Enter a whole number for days.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtDays.Focus();
return;
}
Maybe it's even better to use uint.TryParse
since that prevents the -
sign, but that depends on if negative days are possible.
But you should consider to use the NumericUpDown
-control