设计思路:

用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. php性能剖析的几款软件

    1. xhprof (http://pecl.php.net/package/xhprof)   facebook  2009年开源 2. xdebug 3. valgrind 4. cachegri ...

  2. 创建Unity3D的MacOS Plugin的正确姿势

    http://www.tedlindstrom.se/how-to-link-dylibs-into-unity3d/ I was roaming around the net looking for ...

  3. spin.js

    $ajax提交,菊花加载的方式和位置: $.ajax({ type: "get", url: "http://www.xxx.com/test.html", b ...

  4. 学习微信小程序之css9内边距

    padding内边距 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  5. 转:Delphi的类与继承(VB与delphi比较)

    既然已经做出了com程序用delphi来开发的决定,那当然就要对delphi进行一些深入的了解.有人说delphi是一个用控件堆砌起来的工具,和vb没什么两样:也有人说dephi实际上是面向过程的,他 ...

  6. RPC原理及RPC实例分析

    在学校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 1 2 3 4 5 6 public class ...

  7. php js数组问题

    <script type="text/javascript"> var a = new Array(); a = "a"; a = "b& ...

  8. 关闭rdlc报表打印预览后,关闭客户端,抛出异常“发生了应用程序级的异常 将退出”

    问题:关闭rdlc报表打印预览后,关闭客户端,抛出异常“发生了应用程序级的异常 将退出” 办法:在容纳ReportViewer的窗体后台代码中,添加如下代码即可 protected override ...

  9. touches 事件捕获不到

    在UIView上加载了一个UIScrollView(全屏),touches 事件捕获不到了 原因:UIView的touch事件被UIScrollView捕获了,无法传递下去 解决方法:写一个UIScr ...

  10. 7_nodejs angularjs

    webstrom使用: ctrl+b/点击,代码导航,自动跳转到定义 ctrl+n跳转指定类 ctrl+d复制当前行ctrl+enter另起一行ctrl+y删除当前行 ctrl+alt/shift+b ...