using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _2计算器练习
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str1 = tb_one.Text;
            string str2 = tb_two.Text;
            //判断是否为整数
            int i1, i2;
            if (!int.TryParse(str1, out i1)) {
                MessageBox.Show("第一个数值不是合法的整数!");
                return;
            }
            if (!int.TryParse(str2, out i2)) {
                MessageBox.Show("第二个数值不是合法的整数!");
                return;
            }
            int sum = i1 + i2;
            //这里要按整数转换为string类型以后在赋值给tb_sum.Text
            tb_sum.Text = Convert.ToString(sum);
        }


    }
}

  

相关文章:

  • 2022-01-08
  • 2021-04-19
  • 2021-09-13
  • 2021-11-15
  • 2021-12-02
  • 2021-10-25
  • 2022-01-18
  • 2021-11-09
猜你喜欢
  • 2021-07-03
  • 2021-12-29
  • 2021-12-04
  • 2021-07-05
  • 2022-01-27
  • 2021-12-19
  • 2021-09-08
相关资源
相似解决方案