Friday, May 12, 2006

validate positive integer from user input

uint holds only positive numbers, this event checks if the input is a validate positive integer, otherwise throw error using C#.NET

private void button1_Click(object sender, EventArgs e)

{

uint value = 0;

if (!uint.TryParse(textBox1.Text, out value) value == 0)

{MessageBox.Show("Wrong format");

return;}

textBox2.Text = value.ToString();

}

No comments: