1 private void button1_Click(object sender, EventArgs e) 2 { 3 string str = textBox1.Text; 4 char first = str[0]; 5 string second = str.Substring(1); 6 textBox1.Text = second + first; 7 } 8 9 private void button2_Click(object sender, EventArgs e) 10 { 11 string str = textBox1.Text; 12 string first = str.Substring(str.Length-1); 13 string second = str.Substring(0, str.Length - first.Length); 14 textBox1.Text = first + second; 15 }
1 namespace WindowsFormsApplication1 2 { 3 public partial class Form1 : Form 4 { 5 public Form1() 6 { 7 InitializeComponent(); 8 } 9 //private int remeber; 10 //public int Remeber 11 //{ 12 // get; 13 // set; 14 //} 15 private int remeber = 0; 16 private void button1_Click(object sender, EventArgs e) 17 { 18 string name = this.textBox1.Text; 19 string pwd = this.textBox2.Text; 20 if (name == "admin" && pwd == "888888") 21 { 22 MessageBox.Show("登录成功"); 23 } 24 else 25 { 26 remeber++;//局部变量每次运行完毕都会销毁,下次再运行,会重新初始化,而类字段,只要对象不销毁,就会一直保持对象的字段值。 27 if (remeber >= 3) 28 { 29 MessageBox.Show("已经超过3次,登录失败。"); 30 Application.Exit(); 31 } 32 MessageBox.Show("登录失败"); 33 } 34 } 35 private void button2_Click(object sender, EventArgs e) 36 { 37 string old = this.textBox3.Text; 38 string newpwd = this.textBox4.Text; 39 string newpwd2 = this.textBox5.Text; 40 if (old == newpwd) 41 { 42 MessageBox.Show("修改后的密码不能和旧密码相同"); 43 return; 44 } 45 else if (newpwd != newpwd2) 46 { 47 MessageBox.Show("密码修改不一致"); 48 return; 49 } 50 else 51 { 52 MessageBox.Show("密码修改成功"); 53 } 54 } 55 private void button3_Click(object sender, EventArgs e) 56 { 57 string maxname = ""; 58 int maxscore = -1; 59 string[] arrays = textBox6.Lines; 60 foreach (string array in arrays) 61 { 62 string[] a = array.Split('='); 63 string name = a[0]; 64 string score = a[1]; 65 int scoretemp = Convert.ToInt32(score); 66 if (scoretemp > maxscore) 67 { 68 maxscore = scoretemp; 69 maxname = name; 70 } 71 } 72 MessageBox.Show("第一名" + maxname + ",成绩" + maxscore); 73 } 74 } 75 }