设计思路:

用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 = ;//总计的个数
public static int right = ;//正确的个数
int n = ;
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[];
n1 = File.ReadAllLines("n1.txt");//数值一的文档
textBox1.Text = n1[n];
string[] n2 = new string[];
n2 = File.ReadAllLines("n2.txt");
label4.Content = n2[n];
string[] n3 = new string[];
n3 = File.ReadAllLines("n3.txt");
textBox2.Text = n3[n];
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)) * ).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;
}
}
}

运行过程的各部分显示为以下图片:

WPF计算的更多相关文章

  1. C#/WPF 计算字串的真实长度,调整控件的宽度

    下面函数是经常用到的计算字串长度的方法:         private double MeasureTextWidth(String str, string fontName, double fon ...

  2. WPF 3D:MeshGeometry3D的定义和光照

    原文 WPF 3D:MeshGeometry3D的定义和光照 由于WPF计算光照会根据整个平面的方向向量,所以如果在不同面上使用同一个点可能会达到不同的光照效果.让我们用不同的定义Mesh的方法来演示 ...

  3. 【WPF学习】第三十九章 理解形状

    在WPF用户界面中,绘制2D图形内容的最简单方法是使用形状(shape)——专门用于表示简单的直线.椭圆.矩形以及多变形的一些类.从技术角度看,形状就是所谓的绘图图元(primitive).可组合这些 ...

  4. 计算照片的面积(WPF篇)

    昨天,老周突发其想地给大伙伴们说了一下UWP应用中计算照片面积的玩法,而且老周也表示会提供WPF版本的示例.所以,今天就给大伙们补上吧. WPF是集成在.net框架中,属于.net的一部分,千万不要跟 ...

  5. WPF实现强大的动态公式计算

    数据库可以定义表不同列之间的计算公式,进行自动公式计算,但如何实现行上的动态公式计算呢?行由于可以动态扩展,在某些应用场景下将能很好的解决实际问题. 1.VS2012新建一个WPF应用程序WpfApp ...

  6. WPF DEV gridcontrol 自定义计算列(TotalSummary)

    /// <summary> /// 自定义计算列 /// </summary> /// <param name="sender"></pa ...

  7. [WPF系列]-DataBinding 绑定计算表达式

            Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={Stat ...

  8. 年度巨献-WPF项目开发过程中WPF小知识点汇总(原创+摘抄)

    WPF中Style的使用 Styel在英文中解释为”样式“,在Web开发中,css为层叠样式表,自从.net3.0推出WPF以来,WPF也有样式一说,通过设置样式,使其WPF控件外观更加美化同时减少了 ...

  9. WPF - 属性系统 - APaas(AttachedProperty as a service)

    是的,文章的题目看起来很牛,我承认. 附加属性是WPF中的一个非常重要的功能.例如在设置布局的过程中,软件开发人员就常常通过DockPanel的Dock附加属性来设置其各个子元素所处的布局位置.同样地 ...

随机推荐

  1. xml之dom4j解析

    * 使用dom4j解析xml 实例在java520里面 TextDom4j * dom4j,是一个组织,针对xml解析,提供解析器dom4j * dom4j不是javase的一部分,想要使用第一步需要 ...

  2. direct path read

    在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读的,所以不存在direct pa ...

  3. 3.View绘制分析笔记之onLayout

    上一篇文章我们了解了View的onMeasure,那么今天我们继续来学习Android View绘制三部曲的第二步,onLayout,布局. ViewRootImpl#performLayout pr ...

  4. NXP恩智浦P87C51/52/54/58/591芯片解密单片机破解多少钱?

    NXP恩智浦P87C51/52/54/58/591芯片解密单片机破解 芯片解密型号: P87C51x2.P87C52x2.P87C54x2.P87C58x2.P87C591  单片机解密 #####[ ...

  5. Web Applicationservlet,cookie,session

    Web Application简介: Web Application NameWEB-INFweb.xml 该web application的配置文件lib 该web application用到的依赖 ...

  6. hellocharts的折线图与柱状图的结合之ComboLineColumnChartView

    哼哼,网上找了半天都不全,所以决定自己写一个完整的可以直接贴代码的 test.xml <?xml version="1.0" encoding="utf-8&quo ...

  7. mysql索引总结----mysql 索引类型以及创建

    文章归属:http://feiyan.info/16.html,我想自己去写了,但是发现此君总结的非常详细.直接搬过来了 关于MySQL索引的好处,如果正确合理设计并且使用索引的MySQL是一辆兰博基 ...

  8. linux 常用命令

    //创建目录mkdir//创建中间没有路径的文件夹mkdir -p //删除文件rm//强制删除文件rm -f//删除目录rmdir//删除多个目录rmdir -p //输出当前环境根路径echo $ ...

  9. fmt 标签格式化 日期

    <td class='center'> <fmt:formatDate value="${RecordMail.SendTime }" pattern=" ...

  10. 如何解决插入Oracle数据中文为乱码问题

    1.首先,Oracle查询编码:select * from v$nls_parameters;//看看是否GBK 2.如果是用Servlet或者别的,插入数据之前输出一下,看看是否乱码.比如: doP ...