简单计算器设计(WPF)
2024-08-29 20:10:59
要求:
文本框居中,用户不能修改运算结果 当用户选择不同的运算类型时 下方GroupBox的标题与所选运算类型相对应 且文本框数字立即清空 单击【计算】按钮时 如果文本框输入的内容非法 结果文本框显示问号
运行效果:
XAML:
后台代码:
namespace A._2._2
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Btn_Click(object sender, RoutedEventArgs e)
{
if(!int.TryParse(tb1.Text,out int a) || !int.TryParse(tb2.Text,out int b))
{
tb3.Text = "?";
}else if (addbtn.IsChecked == true)
{
tb3.Text = int.Parse(tb1.Text) + int.Parse(tb2.Text)+"";
}
else if (subbtn.IsChecked == true)
{
tb3.Text = int.Parse(tb1.Text) - int.Parse(tb2.Text)+"";
}
else if (mulbtn.IsChecked == true)
{
tb3.Text = int.Parse(tb1.Text) * int.Parse(tb2.Text)+"";
}
else if (divbtn.IsChecked == true)
{
tb3.Text = int.Parse(tb1.Text) / int.Parse(tb2.Text)+"";
}
else if (delbtn.IsChecked == true)
{
tb3.Text = int.Parse(tb1.Text) % int.Parse(tb2.Text)+"";
}
} private void Radiobtn_Click(object sender, RoutedEventArgs e)
{
if (addbtn.IsChecked == true)
{
tbox.Text = "加法";
lb1.Content = "+";
tb1.Clear();
tb2.Clear();
tb3.Clear();
}
else if (subbtn.IsChecked == true)
{
tbox.Text = "减法";
lb1.Content = "-";
tb1.Clear();
tb2.Clear();
tb3.Clear();
}
else if (mulbtn.IsChecked == true)
{
tbox.Text = "乘法";
lb1.Content = "*";
tb1.Clear();
tb2.Clear();
tb3.Clear();
}
else if (divbtn.IsChecked == true)
{
tbox.Text = "除法";
lb1.Content = "/";
tb1.Clear();
tb2.Clear();
tb3.Clear();
}
else if (delbtn.IsChecked == true)
{
tbox.Text = "取模";
lb1.Content = "%";
tb1.Clear();
tb2.Clear();
tb3.Clear();
}
}
}
}
最新文章
- 新版微信h5视频自动播放
- arcgis对谷歌遥感影像拼接
- SQL图形化操作设置级联更新和删除
- Linux DHCP通过OPTION43为H3C的AP下发AC地址(总结)
- Web3D编程总结——3D碰撞检测初探
- 图文教您轻松学会用PS设计制作名片
- C# 中经常用到的HTTP请求类,已封装get,post,delete,put
- php_公共方法01_传入数组_打印可见信息
- 为outlook增加“邮件召回”功能
- ACdream 1007
- shell中的条件表达式
- hdu1256
- day05-(validate&;bootstred)
- Codeforces 781D Axel and Marston in Bitland 矩阵 bitset
- Docker 与 虚拟机比较
- es 基于match_phrase的模糊匹配原理及使用
- 解决linux下无线网卡被物理禁用问题
- 在SecureCRT中做make menuconfig乱码
- if判断比较详解
- JSP+Servlet+JavaBean实现数据库的增删改查
热门文章
- R 语言输入输出 读取命令函参数
- Spring系列(2):Spring框架
- 【转】gdb typeid 详解
- Net core学习系列(九)——Net Core配置
- 微信小程序调用微信支付接口
- Oracle JDBC prefetch: how to avoid running out of RAM
- grpc使用记录(二)简单同步服务实例
- 图片上传: ajax-formdata-upload
- git clone或者git clone时遇到gnutls_handshake() failed: An unexpected TLS packet was received.如何处理?
- groupby 的妙用(注意size和count)