今天,闲着没事,就自己做了一个小小的计算器。。。虽说自己刚学wp8开发没多长时间,望大神多多指教。。
1.这是前台页面的代码

<Grid x:Name="ContentPanel" Grid.Row="" Margin="10,0,14,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137*"/>
<ColumnDefinition Width="91*"/>
</Grid.ColumnDefinitions>
<TextBox HorizontalAlignment="Right" Name="txtNum" TextWrapping="Wrap" VerticalAlignment="Top" Width="" Margin="0,23,0,0" Grid.ColumnSpan="" FontSize="29.333"/>
<Canvas HorizontalAlignment="Left" Height="auto" Margin="10,102,0,0" VerticalAlignment="Top" Width="auto"/>
<Grid HorizontalAlignment="Left" Height="" Margin="10,95,0,0" VerticalAlignment="Top" Width="" ShowGridLines="True" Grid.ColumnSpan="" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="108*"/>
<ColumnDefinition Width="108*"/>
<ColumnDefinition Width="108*"/>
<ColumnDefinition Width="108*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="117*"/>
<RowDefinition Height="117*"/>
<RowDefinition Height="117*"/>
<RowDefinition Height="117*"/>
<RowDefinition Height="117*"/>
</Grid.RowDefinitions>
<Button Content="" Name="btn9" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btn9_Click"/>
<Button Content="" Name="btn8" HorizontalAlignment="Left" Margin="106,9,0,0" VerticalAlignment="Top" Height="" Width="" Grid.ColumnSpan="" FontSize="" Click="btn8_Click"/>
<Button Content="" Name="btn7" Grid.Column="" HorizontalAlignment="Left" Margin="104,10,0,0" VerticalAlignment="Top" Height="" Grid.ColumnSpan="" Width="" FontSize="" Click="btn7_Click"/>
<Button Content="+" Name="btnAdd" Grid.Column="" HorizontalAlignment="Left" Margin="5,9,-4,0" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btnAdd_Click"/>
<Button Content="" Name="btn6" HorizontalAlignment="Left" Margin="0,9,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btn6_Click"/>
<Button Content="" Name="btn5" Grid.Column="" HorizontalAlignment="Left" Margin="0,10,0,0" Grid.Row="" VerticalAlignment="Top" Width="" Height="" FontSize="" Click="btn5_Click"/>
<Button Content="" Name="btn4" Grid.Column="" HorizontalAlignment="Left" Margin="3,10,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Grid.ColumnSpan="" Width="" FontSize="" Click="btn4_Click"/>
<Button Content="-" Name="btnj" Grid.Column="" HorizontalAlignment="Left" Margin="5,10,-4,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btnj_Click"/>
<Button Content="" Name="btn3" HorizontalAlignment="Left" Margin="2,9,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btn3_Click"/>
<Button Content="" Name="btn2" Grid.Column="" HorizontalAlignment="Left" Margin="0,10,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btn2_Click"/>
<Button Content="" Name="btn1" Grid.Column="" HorizontalAlignment="Left" Margin="5,10,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Grid.ColumnSpan="" Width="" FontSize="" Click="btn1_Click"/>
<Button Content="*" Name="btnchen" Grid.Column="" HorizontalAlignment="Left" Margin="10,10,-9,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btnchen_Click"/>
<Button Content="" Name="btn0" HorizontalAlignment="Left" Margin="0,10,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btn0_Click"/>
<Button Content="." Name="btnDot" Grid.Column="" HorizontalAlignment="Left" Margin="0,9,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btnDot_Click"/>
<Button Content="x^2" Name="pingfang" Grid.Column="" HorizontalAlignment="Left" Margin="3,10,0,0" Grid.Row="" VerticalAlignment="Top" Height="" Grid.ColumnSpan="" Width="" FontSize="29.333" FontWeight="Bold" Click="pingfang_Click" />
<Button Content="/" Name="btnchu" Grid.Column="" HorizontalAlignment="Left" Margin="10,10,-9,0" Grid.Row="" VerticalAlignment="Top" Height="" Width="" FontSize="" Click="btnchu_Click"/>
<Button Content="清除" Name="btnq" HorizontalAlignment="Left" Margin="-3,0,0,-2" VerticalAlignment="Top" Height="" Width="" FontSize="" Grid.Row="" Grid.ColumnSpan="" Click="btnq_Click_1"/>
<Button Content="等于" Name="btndeng" Grid.Column="" HorizontalAlignment="Left" Margin="104,0,-4,-2" VerticalAlignment="Top" Height="" Grid.ColumnSpan="" Width="" FontSize="" Grid.Row="" Click="btndeng_Click_1"/>
</Grid>
<TextBox HorizontalAlignment="Left" Name="txtOld" Height="" Margin="0,-40,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="" Grid.ColumnSpan="" FontSize="29.333"/> </Grid>

2. 这里是后台代码,我都写了注释。。

 private static string num;
private static string sign;
private void btn9_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + "";
} private void btn8_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + "";
} private void btn7_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + "";
} private void btnAdd_Click(object sender, RoutedEventArgs e) //加号
{
num = txtNum.Text;
txtOld.Text = num;
txtNum.Text = "";
sign = "+";
} private void btn6_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + "";
} private void btn5_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + "";
} private void btnq_Click_1(object sender, RoutedEventArgs e) //清除
{ txtNum.Text = "";
txtOld.Text = ""; } private void btn4_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + ""; } private void btnj_Click(object sender, RoutedEventArgs e) //减号
{
num = txtNum.Text;
txtOld.Text = num;
txtNum.Text = "";
sign = "-";
} private void btn3_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + ""; } private void btn2_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + ""; } private void btn1_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + ""; } private void btnchen_Click(object sender, RoutedEventArgs e) //乘法
{
num = txtNum.Text;
txtOld.Text = num;
txtNum.Text = "";
sign = "*";
} private void btn0_Click(object sender, RoutedEventArgs e)
{
txtNum.Text = txtNum.Text + ""; }
private void btnDot_Click(object sender, RoutedEventArgs e) //小数点
{
txtNum.Text = txtNum.Text + ".";
} private void pingfang_Click(object sender, RoutedEventArgs e) //平方
{
num = txtNum.Text.Trim();
try
{
txtNum.Text = (double.Parse(num) * double.Parse(num)).ToString();
}
catch (Exception ex)
{
txtNum.Text = "Error";
return;
}
} private void btndeng_Click_1(object sender, RoutedEventArgs e) //等于
{
if (txtNum.Text =="")
{
return;
} string bb=txtNum.Text.Trim();
if (string.IsNullOrEmpty(num))
{
txtOld.Text =bb;
txtNum.Text = "";
}
else
{
string endResult = GetResult(num, bb, sign);
txtOld.Text = endResult;
txtNum.Text = "";
num = "";
} }
public string GetResult(string num,string m,string option)
{
try
{
double result1 = double.Parse(num);
double mm = double.Parse(m);
if (mm == && option == "/")
{
return "Error";
}
switch (option)
{
case "+": return (result1 + mm).ToString(); break;
case "-": return (result1 - mm).ToString(); break;
case "*": return (result1 * mm).ToString(); break;
case "/": return (result1 / mm).ToString(); break;
default: return "Error";
}
}
catch (Exception ex)
{
return "Error";
} } private void btnchu_Click(object sender, RoutedEventArgs e) //除
{
num = txtNum.Text;
txtOld.Text = num;
txtNum.Text = "";
sign = "/";
}

3.这是用wp8手机模拟的效果图片

在WIndowsPhone8 上制作的简单的计算器的更多相关文章

  1. 使用qt制作一个简单的计算器

    前言:今天使用qt制作了一个很简单的计算器,觉得挺有意思的,所以在这里跟大家分享一下. 这里先跟大家说说使用到的函数: 一.槽连接函数 connect(信号发送者,发送的信号,信号接收者,信号接收者的 ...

  2. WinForm 制作一个简单的计算器

    namespace WindowsFormsApplication6 { public partial class Form1 : Form { //存储上次点击了什么按钮,0代表什么都没有点击,1代 ...

  3. 留念 C语言第一课简单的计算器制作

    留念 C语言第一课简单的计算器制作 学C语言这么久了.  /* 留念 C语言第一课简单的计算器制作 */   #include<stdio.h>  #include<stdlib.h ...

  4. js制作简单的计算器

    学着做了一个简单的计算器!记录记录!哈哈 <!DOCTYPE html> <html> <head> <title>简单的计算器</title&g ...

  5. 01.Java 开发简单的计算器

    难度为一般,适合具有 Java 基础和 Swing 组件编程知识的用户学习一. 实验介绍1.1 实验内容本次实验利用Java开发一个可以进行简单的四则运算的图形化计算器,会使用到 Java Swing ...

  6. CSS制作一个简单网页的下拉导航栏

    网页下拉导航栏的制作 网页下拉导航栏的制作很简单,只需要运用好CSS中伪选择器. 首先说明几个简单的伪选择器(比较常用的): link:连接平常的状态 visited:连接被访问过之后 hover:鼠 ...

  7. iOS实用技能扩展-静态库的制作与简单使用

    前言:此文是关于静态库的概念描述,如何制作及简单调试使用,不同版本的说明与场景使用. 1.关于库的简介: 库可以分为2种类型 开源库 公开源代码,能看到具体实现 比如SDWebImage.AFNetw ...

  8. 教学项目之-通过Python实现简单的计算器

    教学项目之-通过Python实现简单的计算器   计算器开发需求 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/ ...

  9. css制作最简单导航栏

    css制作最简单导航栏

随机推荐

  1. 硬件开发之bt输出---BT656/BT601/BT1120协议以及DM365/DM355/DM6467上使用的YUV颜色空间说明

    http://blog.csdn.net/zhouzhuan2008/article/details/17168133

  2. java类载入器——ClassLoader

    Java的设计初衷是主要面向嵌入式领域,对于自己定义的一些类,考虑使用依需求载入原则.即在程序使用到时才载入类,节省内存消耗,这时就可以通过类载入器来动态载入. 假设你平时仅仅是做web开发,那应该非 ...

  3. myecplise、ecplise项目空间优化

    1.代码自动提示补全 Window->preferences->Java->Editor->Content Assist 再右下角Auto activation trigger ...

  4. Cordova打包vue项目(Android)

    准备工作: 安装好必要环境: vue-cli,webpack,node.js,android环境 (http://cordova.axuer.com/docs/zh-cn/latest/guide/p ...

  5. YTU 2556: 空洞

    2556: 空洞 时间限制: 1 Sec  内存限制: 128 MB 提交: 24  解决: 17 题目描述 春天来了,单身的霞姐越发地空虚寂寞,于是她想到一个办法,她认 为只要把英文字母上的洞都涂满 ...

  6. aria2 for mac

    本文是在安装好homebrew前提下 brew install aria2 然后配置参数 cd ~ mkdir .aria2 cd .aria2 vim aria2.conf 以下配置粘贴进去,红色需 ...

  7. 数据库sqlite3的使用-ios中引用方法

    一.简单说明 在iOS中使用SQLite3,首先要添加库文件libsqlite3.dylib和导入主头文件. 导入头文件,可以使用库中的函数(是纯C语言的) 二.具体说明 新建一个项目,在项目的主界面 ...

  8. 并不对劲的p3709:大爷的字符串题

    题目大意 区间众数 题解 莫队 代码 #include<algorithm> #include<cmath> #include<cstdio> #include&l ...

  9. HDU 4891 The Great Pan (题意题+模拟)

    题意:给定一个文章,问你有多少种读法,计算方法有两种,如果在$中,如果有多个空格就算n+1,如果是一个就算2的次方,如果在{}中, 那么就是把每个空格数乘起来. 析:直接模拟,每次计算一行,注意上一行 ...

  10. poj 2187【旋转卡壳模板】

    求平面最远点对 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath& ...