zoukankan      html  css  js  c++  java
  • 老陈 WPF

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.IO;
    namespace 老陈Wpf
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
            public static int Count = 0;
            public static int right = 0;
            int m = 0;
           
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                StreamWriter n1 = File.AppendText("C:\n1.txt");
                n1.WriteLine(textBox1.Text);
                n1.Close();
                StreamWriter n2 = File.AppendText("C:\n2.txt");
                n2.WriteLine(textBox2.Text);
                n2.Close();
                StreamWriter n3 = File.AppendText("C:\n3.txt");
                n3.WriteLine(textBox3.Text);
                n3.Close();
                MessageBox.Show("录题成功");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }
    
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                //出题
                string[] n1 = new string[100];
                n1 = File.ReadAllLines("C:\n1.txt");
                textBox1.Text = n1[m];
                string[] n2 = new string[100];
                n2 = File.ReadAllLines("C:\n2.txt");
                textBox2.Text = n2[m];
                string[] n3 = new string[100];
                n3 = File.ReadAllLines("C:\n3.txt");
                textBox3.Text = n3[m];
                m++;
            }
            //结束
            private void button3_Click(object sender, RoutedEventArgs e)
            {
                textBox5.Text = MainWindow.Count.ToString();//题目总数
                textBox6.Text = MainWindow.right.ToString();
                textBox7.Text = ((MainWindow.right / (double)(MainWindow.Count)) * 100).ToString() + "%";//正确率
            }
    
            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.Key == Key.Enter)
                {
    
                    if (con.answer == int.Parse(textBox4.Text))
                    {
                        MessageBox.Show("回答正确!下一题请按开始按钮!");
                        right++;
                        Count++;
                    }
    
                    else
                    {
    
                        MessageBox.Show("回答错误!下一题请按开始按钮!");
                        Count++;
    
                    }
                    textBox4.Clear();
                }
            }
    
            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                StreamWriter n1 = File.AppendText("C:\n1.txt");
                n1.WriteLine(textBox1.Text);
                n1.Close();
                StreamWriter n2 = File.AppendText("C:\n2.txt");
                n2.WriteLine(textBox2.Text);
                n2.Close();
                StreamWriter n3 = File.AppendText("C:\n3.txt");
                n3.WriteLine(textBox3.Text);
                n3.Close();
                MessageBox.Show("录题成功");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }
        }
    }
    

     封装

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 老陈Wpf
    {
        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;
    
            }
        }
    }
    

      运行的界面如下:

  • 相关阅读:
    测试心得---杂七杂八
    Redis 集群缓存测试要点--关于 线上 token 失效 BUG 的总结
    linux基础
    如何获取新系统的业务逻辑?
    python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon)
    python笔记8-多线程threading之封装式
    redis监控key失效
    使用PageHepler分页
    使用token和redis怎样判断账户是否失效和异地登录
    JSONObject
  • 原文地址:https://www.cnblogs.com/fjhdmn/p/5039851.html
Copyright © 2011-2022 走看看