猪冰龙

导航

c# radiobutton

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Windows;
  6 using System.Windows.Controls;
  7 using System.Windows.Data;
  8 using System.Windows.Documents;
  9 using System.Windows.Input;
 10 using System.Windows.Media;
 11 using System.Windows.Media.Imaging;
 12 using System.Windows.Navigation;
 13 using System.Windows.Shapes;
 14 
 15 
 16 namespace MathsOperators
 17 {
 18     /// <summary>
 19     /// Interaction logic for MainWindow.xaml
 20     /// </summary>
 21 
 22     public partial class MainWindow : Window
 23     {
 24 
 25         public MainWindow()
 26         {
 27             InitializeComponent();
 28         }
 29 
 30         private void calculateClick(object sender, RoutedEventArgs e)
 31         {
 32             try
 33             {
 34                 if ((bool)addition.IsChecked)
 35                     addValues();
 36                 else if ((bool)subtraction.IsChecked)
 37                     subtractValues();
 38                 else if ((bool)multiplication.IsChecked)
 39                     multiplyValues();
 40                 else if ((bool)division.IsChecked)
 41                     divideValues();
 42                 else if ((bool)remainder.IsChecked)
 43                     remainderValues();
 44             }
 45             catch (Exception caught)
 46             {
 47                 expression.Text = "";
 48                 result.Text = caught.Message;
 49             }
 50         }
 51 
 52         private void addValues()
 53         {
 54             int lhs = int.Parse(lhsOperand.Text);
 55             int rhs = int.Parse(rhsOperand.Text);
 56             int outcome;
 57             outcome = lhs + rhs;
 58             expression.Text = lhsOperand.Text + " + " + rhsOperand.Text;
 59             result.Text = outcome.ToString();
 60         }
 61 
 62         private void subtractValues()
 63         {
 64             int lhs = int.Parse(lhsOperand.Text);
 65             int rhs = int.Parse(rhsOperand.Text);
 66             int outcome;
 67             outcome = lhs - rhs;
 68             expression.Text = lhsOperand.Text + " - " + rhsOperand.Text;
 69             result.Text = outcome.ToString();
 70         }
 71 
 72         private void multiplyValues()
 73         {
 74             int lhs = int.Parse(lhsOperand.Text);
 75             int rhs = int.Parse(rhsOperand.Text);
 76             int outcome;
 77             outcome = lhs * rhs;
 78             expression.Text = lhsOperand.Text + " * " + rhsOperand.Text;
 79             result.Text = outcome.ToString();
 80         }
 81 
 82         private void divideValues()
 83         {
 84             float lhs = float.Parse(lhsOperand.Text);
 85             float rhs = float.Parse(rhsOperand.Text);
 86             float outcome;
 87             outcome = lhs / rhs;
 88             expression.Text = lhsOperand.Text + " / " + rhsOperand.Text;
 89             result.Text = outcome.ToString();
 90         }
 91 
 92         private void remainderValues()
 93         {
 94             float lhs = float.Parse(lhsOperand.Text);
 95             float rhs = float.Parse(rhsOperand.Text);
 96             float outcome;
 97             outcome = lhs % rhs;
 98             expression.Text = lhsOperand.Text + " % " + rhsOperand.Text;
 99             result.Text = outcome.ToString();
100         }
101 
102         private void quitClick(object sender, RoutedEventArgs e)
103         {
104             this.Close();
105         }
106     }
107 }
View Code

 

posted on 2017-12-26 22:19  猪冰龙  阅读(652)  评论(0编辑  收藏  举报