简单计算器设计(WPF)
<p>要求:</p><p>文本框居中,用户不能修改运算效果 当用户选择差异的运算范例时 下方GroupBox的标题与所选运算范例相对应 且文本框数字立即清空 单击【计算】按钮时 如果文本框输入的内容非法 效果文本框表现问号</p>
<p>运行效果:</p>
<p><div align="center"></div></p>
<p>XAML:</p>
<p><div align="center"></div></p>
<p> </p>
<p> </p>
<p>后台代码:</p>
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 }<br><br/><br/><br/><br/><br/>来源:<a href="https://www.cnblogs.com/ywfp-lee/archive/2019/09/16/11530821.html" target="_blank">https://www.cnblogs.com/ywfp-lee/archive/2019/09/16/11530821.html</a>
页:
[1]