WPF中实现
计算类的封装
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace wpfone1
{ interface operater1
{ int calculate(int a, int b); } class Add : operater1
{
public int calculate(int a, int b)
{
return a + b; }
} class Sub : operater1
{
public int calculate(int a, int b)
{
return a - b;
}
} class Mul : operater1
{
public int calculate(int a, int b)
{
return a * b;
}
} class Div : operater1
{ public int calculate(int a, int b)
{ if (b == 0)
{ throw new Exception("除数不能为零!"); } else
{ return a / b; } } }
}
用策咯模式实现
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace wpfone1
{
public class Clacuter
{
private operater1 oper1; public Clacuter(string aSS)
{ switch (aSS)
{ case "+": oper1 = new Add(); break; case "-": oper1 = new Sub(); break; case "*": oper1 = new Mul(); break; case "/": oper1 = new Div(); break; } } public int Calculation(int a, int b)
{ return oper1.calculate(a, b); }
}
}
写入类以及清除题库的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; namespace wpfone1
{
class Writes
{
public void inscribe(string a, string b)
{ StreamWriter aaa = new StreamWriter(a, true);
aaa.WriteLine(b);
aaa.Close(); }
public void cleanup(string c, string d, string e)
{
StreamWriter ddd = new StreamWriter(c);
ddd.WriteLine(" ");
ddd.Close();
StreamWriter aaa = new StreamWriter(d);
aaa.WriteLine("");
aaa.Close();
StreamWriter fff = new StreamWriter(e);
fff.WriteLine("");
fff.Close();
}
}
}
window1的设计以及代码

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; namespace wpfone1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void button1_Click(object sender, RoutedEventArgs e)//写入题
{
Writes writ = new Writes();
string fnm = @"one";
string text1 = this.textBox1.Text;
writ.inscribe(fnm, text1);
string fnmm = @"tow";
string text2 = this.textBox2.Text;
writ.inscribe(fnmm, text2);
string fnm1 = @"fuhao";
string text3 = this.comboBox1.Text;
writ.inscribe(fnm1, text3);
textBox1.Clear();
textBox2.Clear();
} private void button2_Click(object sender, RoutedEventArgs e)
{
string a = @"tow";
string b = @"one";
string c = @"fuhao";
Writes clean = new Writes();
clean.cleanup(a, b, c);
} private void button3_Click(object sender, RoutedEventArgs e)//开始做题
{
Window2 wind = new Window2();
wind.ShowDialog(); }
}
}
Window2的设计及代码

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.Shapes;
using System.IO; namespace wpfone1
{
/// <summary>
/// Window2.xaml 的交互逻辑
/// </summary>
public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
}
private int i = 1;
public static int count;
public static int right;
private void button1_Click(object sender, RoutedEventArgs e)
{
duti();
} private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Clacuter clacuter = new Clacuter(textBox2.Text);
int B = clacuter.Calculation(int.Parse(textBox1.Text), int.Parse(textBox3.Text));
if (textBox4.Text == B.ToString())
{ MessageBox.Show("回答正确!");
right++; } else
{ MessageBox.Show("回答错误!"); }
count++;
textBox4.Clear();
duti(); } }
public void duti()
{
string[] line = File.ReadAllLines("one");
if (i < line.Length)
{
textBox1.Text = line[i];
string[] lines = File.ReadAllLines("tow");
textBox3.Text = lines[i];
string[] lin = File.ReadAllLines("fuhao");
textBox2.Text = lin[i]; }
i++;
if (i == line.Length + 1)
{
MessageBox.Show("你的题做完了,可以去休息一下了!");
Window3 win3 = new Window3();
win3.ShowDialog();
}
} private void button2_Click(object sender, RoutedEventArgs e)
{
this.Close();
Window3 win3 = new Window3();
win3.ShowDialog(); }
}
}
window3的设计及代码

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.Shapes; namespace wpfone1
{
/// <summary>
/// Window3.xaml 的交互逻辑
/// </summary>
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
} private void Window_Loaded(object sender, RoutedEventArgs e)
{
textBox1.Text = Window2.right.ToString();
textBox2.Text = (Window2.count - Window2.right).ToString();
textBox3.Text = ((Window2.right / (double)(Window2.count)) * 100).ToString() + "%";
} private void button1_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
测试




总结;
在这里实现感觉跟在windowform中差不太多只有很少的一部分代码有点不一样,用法也有些少许不同!
总的感觉就是在窗体的设计中比较容易操作,感觉比在windowform中更容易些!
WPF中实现的更多相关文章
- 在WPF中使用依赖注入的方式创建视图
在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...
- MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息
MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- MVVM设计模式和WPF中的实现(四)事件绑定
MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(二)数据绑定
MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(一)MVVM模式简介
MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...
- 【WPF】 Timer与 dispatcherTimer 在wpf中你应该用哪个?
源:Roboby 1.timer或重复生成timer事件,dispatchertimer是集成到队列中的一个时钟.2.dispatchertimer更适合在wpf中访问UI线程上的元素 3.Dispa ...
- 在WPF中使用WinForm控件方法
1. 首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2. 在要使用WinForm控 ...
- 【WPF】WPF中的List<T>和ObservableCollection<T>
在WPF中 控件绑定数据源时,数据源建议采用 ObservableCollection<T>集合 ObservableCollection<T> 类:表示一个动态数据集合,在添 ...
随机推荐
- JavaScript判断文件的大小
function getFileSize(obj) {//obj 需要传入的参数为Input的对象 var objValue = obj.value; if (objValue == " ...
- 流媒体学习四------- ortp队列的实现
在ortp中实现了一个通用的队列,每一个队列包括三个实体,分别是队列.消息块和数据块,这三个实体分别对应queue_t.msgb和datab结构体. queue_t的定义如下所示: typedef s ...
- Magento多语言功能
Magento多语言功能是建立在视图(view)基础之上的,可以通过后台创建店铺视图来创建基于Magento的多语言店铺.本文为大家讲解如何创建多语言的功能.首先,进入“管理店铺”节点,如下所示. S ...
- LeetCode -- Triangle 路径求最小和( 动态规划问题)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- sqlserver 四舍五入(转)
select cast(round(12.5,2) as numeric(5,2)) 解释: round()函数,是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入 ...
- PMP--可能会涉及到的计算题
一.进度管理里的历时三点估算历时的三点估算可能会出现在进度管理的计算题里.以下公式,大家要记住:说一下历时的三点估算中的几个值:1.最有可能的历时估算:Tm2.最乐观的历时估算: To3.最悲观的历时 ...
- 招聘一个靠谱的iOS》面试题参考答案(上)
说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外,其他54道均为简答题. 博文中给出了高质量的面试题,但是未给出答案, ...
- Spring中的@response和@request注解
@response 标注对象返回的格式为json文本 @requestBody将json对象转换为对应的java类
- thinkphp 最简单的引入百度编辑器的方法
后台肯定是框架了...编辑器放在框架里面... 后台首页比如是这样的... <html> <frameset cols="10%,90%"> <fra ...
- VS2013+qt-vs-addin-1.2.4安装配置
--------------------------开头这部分可以跳过,仅作为笔记----------------------- 我问过的问题: http://www.codeproject.com/ ...