WPF计算
设计思路:
用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计算的更多相关文章
- C#/WPF 计算字串的真实长度,调整控件的宽度
下面函数是经常用到的计算字串长度的方法: private double MeasureTextWidth(String str, string fontName, double fon ...
- WPF 3D:MeshGeometry3D的定义和光照
原文 WPF 3D:MeshGeometry3D的定义和光照 由于WPF计算光照会根据整个平面的方向向量,所以如果在不同面上使用同一个点可能会达到不同的光照效果.让我们用不同的定义Mesh的方法来演示 ...
- 【WPF学习】第三十九章 理解形状
在WPF用户界面中,绘制2D图形内容的最简单方法是使用形状(shape)——专门用于表示简单的直线.椭圆.矩形以及多变形的一些类.从技术角度看,形状就是所谓的绘图图元(primitive).可组合这些 ...
- 计算照片的面积(WPF篇)
昨天,老周突发其想地给大伙伴们说了一下UWP应用中计算照片面积的玩法,而且老周也表示会提供WPF版本的示例.所以,今天就给大伙们补上吧. WPF是集成在.net框架中,属于.net的一部分,千万不要跟 ...
- WPF实现强大的动态公式计算
数据库可以定义表不同列之间的计算公式,进行自动公式计算,但如何实现行上的动态公式计算呢?行由于可以动态扩展,在某些应用场景下将能很好的解决实际问题. 1.VS2012新建一个WPF应用程序WpfApp ...
- WPF DEV gridcontrol 自定义计算列(TotalSummary)
/// <summary> /// 自定义计算列 /// </summary> /// <param name="sender"></pa ...
- [WPF系列]-DataBinding 绑定计算表达式
Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={Stat ...
- 年度巨献-WPF项目开发过程中WPF小知识点汇总(原创+摘抄)
WPF中Style的使用 Styel在英文中解释为”样式“,在Web开发中,css为层叠样式表,自从.net3.0推出WPF以来,WPF也有样式一说,通过设置样式,使其WPF控件外观更加美化同时减少了 ...
- WPF - 属性系统 - APaas(AttachedProperty as a service)
是的,文章的题目看起来很牛,我承认. 附加属性是WPF中的一个非常重要的功能.例如在设置布局的过程中,软件开发人员就常常通过DockPanel的Dock附加属性来设置其各个子元素所处的布局位置.同样地 ...
随机推荐
- webServer-----Spring 集成cxf笔录
目前webserver主要有俩中方式:1,传统的webserver标准集成方式-生成WSDL的xml文档. 2, 基于restful风格的webserver java RESTful We ...
- JSON resource 启示
好久没写博客了,刚走完20000步,不废话了,先吐为快. 上面的en-us.json 是一个简单得不能再简单的json对象,当你写下"key-2": "duplicate ...
- 【Java EE 学习 78 上】【数据采集系统第十天】【Service使用Spring缓存模块】
一.需求分析 调查问卷中或许每一个单击动作都会引发大量的数据库访问,特别是在参与调查的过程中,只是单击“上一页”或者“下一页”的按钮就会引发大量的查询,必须对这种问题进行优化才行.使用缓存策略进行查询 ...
- 提取postgresql数据库中jsonb列的数据
; SELECT t.errmsg,sms_records.* FROM sms_records, jsonb_to_record(result_json) AS t(errmsg text,sid ...
- T-SQL 基本语法
--查询 select DB_ID('B2C') --检查数据库是否存在 if DB_ID('B2C') is not null --使用数据库 use B2C --单引号表示字符串,双引号则不是 U ...
- ChannelHandler
ChannelHandler功能介绍 ChannelHandler类似于Servlet的Filter过滤器,负责对I/O事件或者I/O操作进行拦截和处理,它可以选择性地拦截和处理自己感兴趣的事件,也可 ...
- 老生长谈的$.extend()方法
jq的extend()是jq插件扩展很重要的部分,到这里证明是可以自己在jq的基础上,分为两种方法去扩展或开发,为jq本身添加一个方法,可以理解成扩展静态方法和自定义方法. 今天有看到一篇帖子,对这部 ...
- oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数
花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...
- leanote个人版安装
https://github.com/leanote/leanote/wiki/Leanote-%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%89%88%E8%AF%A6%E7%BB% ...
- js转盘抽奖
这个是很简易的转盘,只用了html,css,js 通过css产生一个转盘上的指针,用js动态改变css中的transparent改变指针的角度.再添加一个背景图片类似于奖项的转盘 <!DOCTY ...