textbox的验证

代码如下:

textBox1.KeyDown += (a, b) =>

    {

        if (b.KeyCode == Keys.Enter)

        {

            textBox2.Focus();

        }

    };

textBox1.Leave += delegate

    {

        int result;

        if (!int.TryParse(textBox1.Text.Trim(), out result))

        {

            MessageBox.Show("fsfd");

            textBox1.Focus();

        }

    };

 

你可能感兴趣的:(text)