Summary: In this job learned the encapsulation, but still do not use the strategy model.
Code for the Form1 form
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;using system.io;namespace old Chen Small stone {public partial class Fo Rm1:form {public Form1 () {InitializeComponent (); } String path = "i:\\ sophomore on \ \ Software Engineering"; public static int count=0; public static int t = 0; public static int right = 0; public static int sum; int j = 0; int i = 0; "*" private void Cheng_click (object sender, EventArgs e) {ysf. Text = "*"; count++; Number2. Focus (); }//"+" private void Jia_click (object sender, EventArgs e) {ysf. Text = "+"; count++; Number2. Focus (); }//"-" private void Jian_click (object sender, EventArgs e) {ysf. Text = "-"; count++;Number2. Focus (); }//Quiz private void Submitan_click (object sender, EventArgs e) {StreamWriter N1 = File.ap Pendtext ("N1.txt"); N1. WriteLine (number1. Text); N1. Close (); StreamWriter fu = file.appendtext ("Fu.txt"); Fu. WriteLine (YSF. Text); Fu. Close (); StreamWriter N2 = File.appendtext ("N2.txt"); N2. WriteLine (number2. Text); N2. Close (); Tiku. Text + = Number1. Text + YSF. Text + number2. Text + Deng. Text + "\ n"; j + +; Number1. Text = ""; Number2. Text = ""; YSF. Text = ""; Txtsave. Enabled = true; Txtopen. Enabled = true; Number1. Focus (); } private void Timer1_Tick (object sender, EventArgs e) {t = t + 1; Jitime. Text = T.tostring (); }//Start answer private void Start_click (object sender, EventArgs e) {jitime. Text =T.tostring (); Timer1. Enabled = true; Timer1. Interval = 1000; Timer1. Start (); String[] M1 = new STRING[100]; M1 = File.ReadAllLines ("N1.txt"); String[] m2 = new string[100]; M2 = file.readalllines ("Fu.txt"); string[] m3 = new string[100]; M3 = File.ReadAllLines ("N2.txt"); TextBox1.Text = m1[0]; TextBox2.Text = m2[0]; TextBox3.Text = m3[0]; Answer. Focus (); }//Submit answer private void Mit_click (object sender, EventArgs e) {string m = TextBox2.Text; Switch (m) {case ' + ': sum = Int. Parse (TextBox1.Text) + int. Parse (TextBox3.Text); Break Case "-": sum = Int. Parse (TextBox1.Text)-Int. Parse (TextBox3.Text); Break Case "*": sum = Int. Parse (textbox1.text) * int. Parse (TextBox3.Text); Break Default:break; } if (answer. Text = = Sum. ToString ()) right++; Answer. Text = ""; i++; if (I < j) {string[] m1 = new STRING[100]; M1 = File.ReadAllLines ("N1.txt"); String[] m2 = new string[100]; M2 = file.readalllines ("Fu.txt"); string[] m3 = new string[100]; M3 = File.ReadAllLines ("N2.txt"); TextBox1.Text = M1[i]; TextBox2.Text = M2[i]; TextBox3.Text = M3[i]; } else {TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; } answer. Focus (); }//View the title case private void Button1_Click (object sender, EventArgs e) {timer1. Enabled = false; Form2 FRM = new Form2 (); frm. Show (); }//Save private void Txtsave_click (object sender, EventArgs e) {SaveFileDialog txtsavedial og = new SaveFileDialog (); Txtsavedialog.filter = "RTF file (*. RTF) |*. RTF "; if (file.exists (path)) {This.tiku.SaveFile (path, richtextboxstreamtype.richtext); MessageBox.Show ("Save succeeded", "hint message", MessageBoxButtons.OK, Messageboxicon.asterisk); This.tiku.Clear (); Txtsave. Enabled = false; } else {if (txtsavedialog.showdialog () = = DialogResult.OK) {This.tiku.SaveFile (txtsavedialog.filename, Richtextboxstreamtype.richtext); MessageBox.Show ("Save succeeded", "hint message", MessageBoxButtons.OK, Messageboxicon.asterisk); This.tiku.Clear (); Txtsave. Enabled = false; } } }View private void Txtopen_click (object sender, EventArgs e) {OpenFileDialog Txtopendialog = new OpenFileDialog (); Txtopendialog.filter = "RTF file (*. RTF) |*. RTF "; if (txtopendialog.showdialog () = = DialogResult.OK) {path = Txtopendialog.filename; This.tiku.LoadFile (Txtopendialog.filename, Richtextboxstreamtype.richtext); Txtsave. Enabled = false; Txtopen. Enabled = false; MessageBox.Show ("Open successfully", "hint message", MessageBoxButtons.OK, Messageboxicon.asterisk); }} private void Form1_Load (object sender, EventArgs e) {txt TT = new txt (); Tt.text1 (); } }}
Form2 the form code
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 old Chen Small stone {public partial class form2:form< c1/>{public Form2 () { InitializeComponent (); } private void Form2_load (object sender, EventArgs e) {
Textcount. Text = Form1.count.ToString (); Ttishu.text = Form1.right.ToString (); Tlv.text = ((Form1.right/(double) (form1.count)) * 100). ToString () + "%"; Yunss. Text= (form1.t/(double) (Form1.count)). ToString () + "/t"; }} }
TXT-like code
Using system;using system.collections.generic;using system.linq;using system.text;using System.IO;namespace old Chen Small stone { class txt {
Generates three text to hold data public void Text1 () { file.writealltext ("N1.txt", String. Empty); File.writealltext ("Fu.txt", String. Empty); File.writealltext ("N2.txt", String. Empty);}}}
Lao Chen and the small stone operation code