winform  中,两个TEXTBOX  和一个BUTTON
在两个TEXTBOX输入不同数字后 按 BUTTON 做出比较
然后messageBox show出大的数字
如果在TEXTBOX中输入的是其他的非数字的字符, messagebox show出 只能输入数字!
小弟刚学C#  火星了哈 路过的大仙们帮个小忙, 立马给分!!!!!

解决方案 »

  1.   

    private void button1_Click(object sender, EventArgs e)
            {
                int a, b;
                try
                {
                    a = Int32.Parse(textBox1.Text);
                    b = Int32.Parse(textBox2.Text);                MessageBox.Show(a > b ? a.ToString() : b.ToString());
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Digits only!");
                }
            }
      

  2.   

    private void button1_Click(object sender, EventArgs e)
            {
                if(IsNumeric(textBox1.Text) && IsNumeric(textBox2.Text))
                {                MessageBox.Show( (Math.Max( int.Parse(textBox1.Text), int.Parse(textBox2.Text)).ToString() ));
                }
                else
                {
                    MessageBox.Show("不是数字");
                }
            }        static bool IsNumeric(string str)
            {
                System.Text.RegularExpressions.Regex reg1
                    = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
                return reg1.IsMatch(str);
            }