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 _3练习1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string str_width = tb_width.Text; string str_height = tb_height.Text; //判断值是否有效 int i1, i2, sum; if (!int.TryParse(str_width, out i1)) { MessageBox.Show("宽为非整数!"); return; } if (!int.TryParse(str_height, out i2)) { MessageBox.Show("高为非整数!"); return; } sum = i1 * i2; tb_sum.Text = Convert.ToString(sum); } private void button2_Click(object sender, EventArgs e) { string email = tb_email.Text; //进行字符串进行分析,然后放入数组中的 //这里用数组的长度来判断该email是否有效 string[] str = email.Split('@'); if (str.Length != 2) { MessageBox.Show("Email不合法!"); return; } tb_name.Text = str[0]; tb_www.Text = str[1]; } private void button3_Click(object sender, EventArgs e) { //求累加 string str1 = tb_start.Text; string str2 = tb_end.Text; int i1, i2; if (!int.TryParse(str1, out i1)){ MessageBox.Show("第一个数值不是整数!"); return; } if (!int.TryParse(str2, out i2)) { MessageBox.Show("第二个数值不是整数!"); return; } if (i2 <= i1) { MessageBox.Show("第二个值不能小大第一个值!"); return; } int sum = 0; for (int i = i1; i <= i2; i++) { sum += i; } tb_count.Text = Convert.ToString(sum); } } }