码迷,mamicode.com
首页 > 其他好文 > 详细

小石头 封装

时间:2015-12-01 23:10:54      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:

第一个页面

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 老陈
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        private void luti_Click(object sender, EventArgs e)
        {
            StreamWriter n1 = File.AppendText("n1.txt");
            n1.WriteLine(textBox1.Text);
            n1.Close();
            StreamWriter n2 = File.AppendText("n2.txt");
            n2.WriteLine(textBox2.Text);
            n2.Close();
            StreamWriter n3 = File.AppendText("n3.txt");
            n3.WriteLine(textBox3.Text);
            n3.Close();
            richTextBox1.Text += textBox1.Text + textBox2.Text + textBox3.Text+"\n";
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            MessageBox.Show("写入成功");
        }

        private void kaishi_Click(object sender, EventArgs e)
        {//跳转页面
            Form2 frm2 = new Form2();
            frm2.ShowDialog();
        }
    }
}

  运行的界面技术分享

第二个页面

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 老陈
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public static int Count = 0;
        private int t = 60;
        public static int right = 0;
        //总计的个数和正确的个数
        int m = 0;
        private void button1_Click(object sender, EventArgs e)
        {   //时间
            label1.Text = t.ToString();
            timer1.Enabled = true;
            timer1.Interval = 1000;
            timer1.Start();
            //出题
            string[] n1 = new string[100];
            n1 = File.ReadAllLines("n1.txt");
            textBox1.Text = n1[m];
            string[] n2 = new string[100];
            n2 = File.ReadAllLines("n2.txt");
            textBox2.Text = n2[m];
            string[] n3 = new string[100];
            n3 = File.ReadAllLines("n3.txt");
            textBox3.Text = n3[m];
            m++;

        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            //调用;
            int a = int.Parse(textBox1.Text);
            int b = int.Parse(textBox3.Text);
            Char c = Convert.ToChar(textBox2.Text);
            Class1 con = new Class1();
            con.chu(a, b, c);
            if (e.KeyCode == Keys.Enter)
            {

                if (con.answer == int.Parse(textBox4.Text))
                {
                    MessageBox.Show("回答正确!下一题请按开始按钮!");
                    right++;
                    Count++;
                }

                else
                {

                    MessageBox.Show("回答错误!下一题请按开始按钮!");
                    Count++;

                }
                timer1.Enabled = false;
                textBox1.Clear();//清空
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();

            }

        }
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            if (t <= 0)
            {
                timer1.Enabled = false;
                MessageBox.Show("时间到!");
            }
                t = t - 1;
                label1.Text = t.ToString();    
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            textBox4.Enabled = false;
            MessageBox.Show("运算结束!");
            textBox5.Text = Form2.Count.ToString();//题目总数
            textBox6.Text = Form2.right.ToString();
            textBox7.Text = ((Form2.right / (double)(Form2.Count)) * 100).ToString() + "%";//正确率
        }

        
    }
}

  运行的界面技术分享技术分享技术分享

封装如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 老程
{
    class Class1
    {
        public int sum;
        public int answer
        {
            get
            {
                return sum;
            }
        }

        public int chu(int n1, int n2, char fuhao)
        {
            if (fuhao == ‘+‘)
            {
                return sum = n1 + n2;
            }
            else if (fuhao == ‘-‘)
            {
                return sum = n1 - n2;
            }
            else if (fuhao == ‘*‘)
            {
                return sum= n1 * n2;
            }
            return sum;

        }
    
    }
}

  总结:在做这次的封装,遇到了很多困难,从当初的不知道封装是什么,怎么去做,到今天才把这个做好。我知道我的代码不是很好,这是老师布置作业后我开始看我以前C#的书和请教已经完成的同学,然后无数次的测试,修改我的代码,到现在做成这样,不过我的实现功能不是特别全,不会保存,不过我的下一步会完善的,我会继续努力让自己跟上去的。

小石头 封装

标签:

原文地址:http://www.cnblogs.com/fjhdmn/p/5011490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!