幼稚园的学习,只能拿计算器练手,幸好基本没有抄袭别人的,狂躁的我窃喜不已!
这里的代码糟糕的没法形容,毕竟从结构化迁徙到面向对象是一种说不出滋味的爽或不爽。乘法、除法、乘方的功能都没有实现,迫不及待地发出来,当然是显摆显摆。一个值得庆幸的地方是,这里基本没有抄袭的痕迹,都是自己吭吭哧哧拼出来的,还真的有点喜形于色。当然有一点不得不提,我蹩脚的英语居然一点都没有提高。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 WpfApp5
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public decimal xxx;
public char opteration;
public MainWindow()
{
xxx = (decimal)0.0;
opteration = '+';
InitializeComponent();
}
private void Clear_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text = "";
label.Content = "";
label_Copy.Content = "";
xxx = 0;
}
private void _0_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '0';
}
private void _1_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '1';
}
private void _2_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '2';
}
private void _3_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '3';
}
private void _4_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '4';
}
private void _5_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '5';
}
private void _6_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '6';
}
private void Button_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '7';
}
private void _8_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '8';
}
private void _9_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '9';
}
private void _00_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += "00";
}
private void Dot_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
if (textbox.Text.Contains('.'))
;
else
textbox.Text += '.';
}
private void Add_Click(object sender, RoutedEventArgs e)
{
Label mylab = label;
if (tb.Text.Equals(""))
{
mylab.Content = "";
mylab.Content = '+';
opteration = (char)mylab.Content;
}
else {
switch (opteration)
{
case '+':
try
{
xxx += Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '-':
try
{
xxx -= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '*':
try
{
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '/':
try
{
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
}
mylab.Content = "";
mylab.Content = '+';
opteration = (char)mylab.Content;
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
}
private void Sub_Click(object sender, RoutedEventArgs e)
{
Label mylab = label;
if (tb.Text.Equals(""))
{
mylab.Content = "";
mylab.Content = '-';
opteration = (char)mylab.Content;
}
else
{
switch (opteration)
{
case '+':
try
{
xxx += Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '-':
try
{
xxx -= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '*':
try
{
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '/':
try
{
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
}
mylab.Content = "";
mylab.Content = '-';
opteration = (char)mylab.Content;
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
}
private void Mul_Click(object sender, RoutedEventArgs e)
{
Label mylab = label;
// if (tb.Text.TrimEnd('+').Equals('+'))
mylab.Content = "";
mylab.Content = '*';
try
{
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
}
private void Div_Click(object sender, RoutedEventArgs e)
{
Label mylab = label;
// if (tb.Text.TrimEnd('+').Equals('+'))
mylab.Content = "";
mylab.Content = '/';
try
{
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
MessageBox.Show("div 0 error!");
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
}
private void Delete_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
try {
if (textbox.Text.Length > 0)
textbox.Text = textbox.Text.Substring(0, textbox.Text.Length - 1);
}
catch (Exception ee) {
}
}
private void Result_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Unable use!");
}
}
}