ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

简单计算器设计(WPF)

2019-09-16 23:04:31  阅读:250  来源: 互联网

标签:tb2 int Text Clear 计算器 tb1 简单 WPF tb3


要求:

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

运行效果:

XAML:

 

 

后台代码:

 1 namespace A._2._2
 2 {
 3     /// <summary>
 4     /// MainWindow.xaml 的交互逻辑
 5     /// </summary>
 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 }

标签:tb2,int,Text,Clear,计算器,tb1,简单,WPF,tb3
来源: https://www.cnblogs.com/ywfp-lee/p/11530821.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有