WPF计算
2015-12-11 20:36
253 查看
设计思路:
用WPF窗体设计,在第一个数和第二个数的文本框中输入数值,单击录题按钮,数值保存在n1,n2文档中,把要做的题都保存完后,单击开始按钮,开始做题,每做完一道题,按Enter键,进入下一题,同时提示回答是否正确。如果在时间内做完题就单击结束按钮,弹出对话框“答题结束” 总计,正确的个数及正确率显示出来。
MainWindow.xaml设计为:
代码为:
Class.cs代码
运行过程的各部分显示为以下图片:
用WPF窗体设计,在第一个数和第二个数的文本框中输入数值,单击录题按钮,数值保存在n1,n2文档中,把要做的题都保存完后,单击开始按钮,开始做题,每做完一道题,按Enter键,进入下一题,同时提示回答是否正确。如果在时间内做完题就单击结束按钮,弹出对话框“答题结束” 总计,正确的个数及正确率显示出来。
MainWindow.xaml设计为:
代码为:
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 xiaoshitou { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public static int Count = 0;//总计的个数 public static int right = 0;//正确的个数 int n = 0; private void button1_Click(object sender, RoutedEventArgs e) { label4.Content = "+"; } private void button2_Click(object sender, RoutedEventArgs e) { label4.Content = "-"; } private void button3_Click(object sender, RoutedEventArgs e) { label4.Content = "-"; ; } private void button4_Click(object sender, RoutedEventArgs e) { label4.Content = "-"; } private void button5_Click(object sender, RoutedEventArgs e) { StreamWriter n1 = File.AppendText("n1.txt");//第一个数存入第一文档 n1.WriteLine(textBox1.Text); n1.Close(); StreamWriter n2 = File.AppendText("n2.txt");//第二个数存入第二个文档 n2.WriteLine(label4.Content); n2.Close(); StreamWriter n3 = File.AppendText("n3.txt");//结果存入第三个文档 n3.WriteLine(textBox2.Text); n3.Close(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); MessageBox.Show("录题成功"); } private void button6_Click(object sender, RoutedEventArgs e) { string[] n1 = new string[100]; n1 = File.ReadAllLines("n1.txt");//数值一的文档 textBox1.Text = n1 ; string[] n2 = new string[100]; n2 = File.ReadAllLines("n2.txt"); label4.Content = n2 ; string[] n3 = new string[100]; n3 = File.ReadAllLines("n3.txt"); textBox2.Text = n3 ; n++; } private void button7_Click(object sender, RoutedEventArgs e) { textBox3.IsEnabled = false; MessageBox.Show("运算结束!"); textBox4.Text = Count.ToString();//题目总数 textBox5.Text =right.ToString();//正确的个数 textBox6.Text = ((right / (double)(Count)) * 100).ToString() + "%";//正确率 } private void textBox3_KeyDown(object sender, KeyEventArgs e) { int a = int.Parse(textBox1.Text); int b = int.Parse(textBox2.Text); Char c = Convert.ToChar(label4.Content); Class1 con = new Class1(); con.js(a, b, c); if (e.Key == Key.Enter) { if (con.y1 == int.Parse(textBox3.Text)) { MessageBox.Show("回答正确!下一题请按开始按钮!"); right++; Count++; } else { MessageBox.Show("回答错误!下一题请按开始按钮!"); Count++; } //清空 textBox3.Clear(); textBox1.Clear(); textBox2.Clear(); } } } }
Class.cs代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace xiaoshitou { class Class1 { public int result; public int y1 { get { return result; } } public int js(int n1, int n2, char mark) { if (mark == '+') { return result = n1 + n2; } else if (mark == '-') { return result = n1 - n2; } else if (mark == '*') { return result = n1 * n2; } else if (mark == '/') { return result = n1 / n2; } return result; } } }
运行过程的各部分显示为以下图片:
相关文章推荐
- Android读书计划
- 关于Java中List对象的分页思想,按10个或者n个数对list进行分组
- BZOJ 1143 1143: [CTSC2008]祭祀river 最长反链
- 自定义ViewGroup (滚动布局)
- 字符串
- 设计模式系列(十一)外观模式(Facade Pattern)
- 前端技术刊
- Git Bash下载Android源码
- java日志——基本日志+高级日志
- leetcode Count and Say
- leetcode -- Median of Two Sorted Arrays -- 重点有技巧
- 删除重复字符
- 内网渗透学习
- Tomcat环境变量的配置
- SQL 改写 max decode 联合应用
- HTML5 总结 (1)
- tinyos学习笔记2--由"="引出的问题(Blink例程的学习)
- Mybatis 二级缓存
- 集合set
- 7_排序二叉树