简单计算器设计(WPF)

文本框居中,用户不能修改运算结果 当用户选择不同的运算类型时 下方GroupBox的标题与所选运算类型相对应 且文本框数字立即清空 单击【计算】按钮时 如果文本框输入的内容非法 结果文本框显示问号

复制代码
1 namespace A._2._2
2 {
3 ///
4 /// MainWindow.xaml 的交互逻辑
5 ///
6 public partial class MainWindow : Window
7 {
8 public MainWindow()
9 {
10 InitializeComponent();
11 }
12
13 private void Btn_Click(object sender, RoutedEventArgs e)
14 {
15 if(!int.TryParse(tb1.Text,out int a) || !int.TryParse(tb2.Text,out int b))
16 {
17 tb3.Text = “?”;
18 }else if (addbtn.IsChecked == true)
19 {
20 tb3.Text = int.Parse(tb1.Text) + int.Parse(tb2.Text)+"";
21 }
22 else if (subbtn.IsChecked == true)
23 {
24 tb3.Text = int.Parse(tb1.Text) - int.Parse(tb2.Text)+"";
25 }
26 else if (mulbtn.IsChecked == true)
27 {
28 tb3.Text = int.Parse(tb1.Text) * int.Parse(tb2.Text)+"";
29 }
30 else if (divbtn.IsChecked == true)
31 {
32 tb3.Text = int.Parse(tb1.Text) / int.Parse(tb2.Text)+"";
33 }
34 else if (delbtn.IsChecked == true)
35 {
36 tb3.Text = int.Parse(tb1.Text) % int.Parse(tb2.Text)+"";
37 }
38 }
39
40 private void Radiobtn_Click(object sender, RoutedEventArgs e)
41 {
42 if (addbtn.IsChecked == true)
43 {
44 tbox.Text = “加法”;
45 lb1.Content = “+”;
46 tb1.Clear();
47 tb2.Clear();
48 tb3.Clear();
49 }
50 else if (subbtn.IsChecked == true)
51 {
52 tbox.Text = “减法”;
53 lb1.Content = “-”;
54 tb1.Clear();
55 tb2.Clear();
56 tb3.Clear();
57 }
58 else if (mulbtn.IsChecked == true)
59 {
60 tbox.Text = “乘法”;
61 lb1.Content = “*”;
62 tb1.Clear();
63 tb2.Clear();
64 tb3.Clear();
65 }
66 else if (divbtn.IsChecked == true)
67 {
68 tbox.Text = “除法”;
69 lb1.Content = “/”;
70 tb1.Clear();
71 tb2.Clear();
72 tb3.Clear();
73 }
74 else if (delbtn.IsChecked == true)
75 {
76 tbox.Text = “取模”;
77 lb1.Content = “%”;
78 tb1.Clear();
79 tb2.Clear();
80 tb3.Clear();
81 }
82 }
83 }
84 }
东莞网站建设www.zg886.cn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值