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

 

转载于:https://www.cnblogs.com/zhubinglong/p/8120309.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值