The Strategy mode of Calculator

Source: Internet
Author: User

First, the code implementation

Form1 Code

namespaceszys{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }              Public Static intright =0;  Public Static intCount =0; Private intT; stringPath =". \text1.txt"; intA =0; Private voidButton5_click (Objectsender, EventArgs e) {Count++; StreamWriter baocun1= File.appendtext ("Baocun1.txt"); Baocun1.            WriteLine (TextBox1.Text); Baocun1.            Close (); StreamWriter baocun2= File.appendtext ("Baocun2.txt"); Baocun2.            WriteLine (Textbox4.text); Baocun2.            Close (); StreamWriter Baocun3= File.appendtext ("Baocun3.txt"); Baocun3.            WriteLine (TextBox2.Text); Baocun3.            Close (); richTextBox1.Text+ = TextBox1.Text + textbox4.text + TextBox2.Text + label2. Text + TextBox3.Text +"\ n";            Textbox1.clear ();            Textbox4.clear ();        Textbox2.clear (); }        Private voidBtnsave_click (Objectsender, EventArgs e)//Save the test questions;{SaveFileDialog Txtsavedialog=NewSaveFileDialog (); Txtsavedialog.filter="text Document (*.txt) |*.txt"; if(file.exists (path)) { This. Richtextbox1.loadfile (path, richtextboxstreamtype.plaintext); MessageBox.Show ("saved successfully","Prompt Information", MessageBoxButtons.OK, Messageboxicon.asterisk);  This. Richtextbox1.clear (); Btnsave. Enabled=false; }            Else            {                if(Txtsavedialog.showdialog () = =DialogResult.OK) { This. Richtextbox1.savefile (Txtsavedialog.filename, Richtextboxstreamtype.plaintext); MessageBox.Show ("saved successfully","Prompt Information", MessageBoxButtons.OK, Messageboxicon.asterisk);  This. Richtextbox1.clear (); Btnsave. Enabled=false; Button1. Visible=true; }            }        }        Private voidButton1_Click (Objectsender, EventArgs e)//open the question;{OpenFileDialog Txtopendialog=NewOpenFileDialog (); Txtopendialog.filter="text Document (*.txt) |*.txt"; if(Txtopendialog.showdialog () = =DialogResult.OK) {path=Txtopendialog.filename;  This. Richtextbox2.loadfile (Txtopendialog.filename, Richtextboxstreamtype.plaintext); Btnsave. Enabled=false; Button1. Enabled=false; MessageBox.Show ("Open Success","Prompt Information", MessageBoxButtons.OK, Messageboxicon.asterisk); }        }        Private voidButton2_Click (Objectsender, EventArgs e)//add a calculation question;{textbox1.enabled=false; Textbox2.enabled=false; Textbox4.enabled=false; Textbox1.backcolor=Color.yellow; Textbox4.backcolor=Color.yellow; Textbox2.backcolor=Color.yellow; Textbox3.backcolor=Color.yellow; string[] m =New string[ -]; M= File.ReadAllLines ("Baocun1.txt"); TextBox1.Text=M[a]; string[] n =New string[ -]; N= File.ReadAllLines ("Baocun2.txt"); Textbox4.text=N[a]; string[] v =New string[ -]; V= File.ReadAllLines ("Baocun3.txt"); TextBox2.Text=V[a]; A++; }        Private voidTextbox3_mouseclick (Objectsender, MouseEventArgs e)//timing;{label3. Text=t.tostring (); Timer1. Enabled=true; Timer1. Interval= +; Timer1.        Start (); }        Private voidTimer1_Tick (Objectsender, EventArgs e) {T= T +1; Label3. Text=t.tostring (); }        Private voidButton3_Click (Objectsender, EventArgs e) {MessageBox.Show ("altogether"+ Label3. Text +"seconds"); Form2 Frm2=NewForm2 (); Frm2.        ShowDialog (); }        Private voidButton4_Click (Objectsender, EventArgs e) {            //call;Szys.celuemoshi.Sub.yunsuanfu Clacuter =NewSzys.celuemoshi.Sub.yunsuanfu (Textbox4.text); intresult = Clacuter. Calculation (int. Parse (TextBox1.Text),int.                           Parse (TextBox2.Text)); if(textbox3.text==result. ToString ()) {MessageBox.Show ("Congratulations, little one! Answer right! "); Right++; Count++; }                Else{MessageBox.Show ("answer the wrong, continue to refuel! Kids"); Count++;                } textbox1.clear ();                Textbox2.clear ();                Textbox3.clear ();            Textbox4.clear (); }               }    }

Form2 Code

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceszys{ Public Partial classForm2:form { PublicForm2 () {InitializeComponent (); }        Private voidForm2_load (Objectsender, EventArgs e) {TextBox1.Text=Form1.Count.ToString (); TextBox2.Text=Form1.right.ToString (); Textbox4.text= ((Form1.right/(Double) (Form1.count)) * -). ToString () +"%"; }     } }

second, the test

The Strategy mode of Calculator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.