栏目:应届生落户    人气:0    日期:2023-03-08

免费提供最新落户政策及一对一落户方案

留学生/应届生/非婚子女 落户咨询

落户咨询二维码  

C#WPF计算器!一个刚刚入门一个星期Csharp的应届生!

(C#WPF计算器!一个刚刚入门一个星期Csharp的应届生!)

  

先入正题吧!

  

1:创建wpf应用。我用的VS是2013!

  

2:创建wpf文件并且起名字!

  

3:起一条虚线

  

3:打开我们电脑基本的计算器,然后我们模仿他来做计算器吧!

  

4:在工具箱找到lable,把他拖进来。并且起一个名字!设置他的属性。

  

4:再然后在工具箱找到button按钮把他拖进来。并且帮他起名字,还有设置他的属性!

  

5:写完整的界面,按钮直接复制粘贴就可以的!下一步进行后台代码!

  

6:定义三个变量存放数据!

  

7:设置按钮0的点击事件!然后数字键复制粘贴就可以了!

  

8:设置符号键,给他赋值!

  

9:设置C按键清除所有!这个问了很多人才找到的C按键清除lable!

  

10:设置等于号按键促发加减乘除!

  

11:然后一个计算器完成了!下面是全部代码!

  

namespaceLVcalculation

  

{

  

??///

  

??///MainWindow.xaml的交互逻辑

  

??///

  

??publicpartialclassMainWindow:Window

  

??{

  

????stringnumber1=null,number2=null,flag=null;//第一个变量存放按下的第一个字符,第二个变量存放按下符号键的字符。第三个存放符号的字符!

  

????publicMainWindow左边()右边

  

????{

  

??????InitializeComponent左边()右边;

  

????}

  

????privatevoidbutton0_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"0";

  

????????lable1.Content=number1;

  

??????}

  

??????else{

  

????????number2=number2+"0";

  

????????lable1.Content=number2;

  

???????

  

??????}

  

????}

  

????privatevoidbutton1_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"1";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"1";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton2_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"2";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"2";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton3_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"3";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"3";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton4_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"4";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"4";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton5_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"5";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"5";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton6_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"6";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"6";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton7_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"7";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"7";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton8_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"8";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"8";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton9_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"9";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"9";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbuttonb_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="-";

  

????}

  

????privatevoidbuttona_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="+";

  

????}

  

????privatevoidbuttone_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="%";

  

????}

  

????privatevoidbuttond_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="/";

  

????}

  

????privatevoidbuttonc_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="*";

  

????}

  

????privatevoidbuttoncc_Click(objectsender,RoutedEventArgse)

  

????{

  

??????this.lable1.Content="";

  

????}

  

????privatevoidbuttongg_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+".";

  

????????lable1.Content=number1;

  

??????}

  

??????else{

  

????????number2=number2+".";

  

????????lable1.Content=number2;

  

???????

  

??????}

  

????}

  

????privatevoidbuttonf_Click(objectsender,RoutedEventArgse)

  

????{

  

??????switch(flag){

  

????????case"+":lable1.Content=Convert.ToString(Convert.ToDouble(number1)+Convert.ToDouble(number2));

  

??????????break;

  

????????case"-":lable1.Content=Convert.ToString(Convert.ToDouble(number1)-Convert.ToDouble(number2));

  

??????????break;

  

????????case"*":lable1.Content=Convert.ToString(Convert.ToDouble(number1)*Convert.ToDouble(number2));

  

??????????break;

  

????????case"/":lable1.Content=Convert.ToString(Convert.ToDouble(number1)/Convert.ToDouble(number2));

  

??????????break;

  

????????case"%":lable1.Content=Convert.ToString(Convert.ToDouble(number1)%Convert.ToDouble(number2));

  

??????????break;

  

??????}

  

??????number1=null;

  

??????number2=null;

  

??????flag=null;

  

????}

  

??}

  

}

  

12:还有一种方法写!注意这个方法的是用textbox,不是用lable。

  

13:下面是这个的全部代码!

  

  

????xmlns=""

  

????xmlns:x=""

  

????Title="为什么我写的计算器这么多bug"Height="350"MaxHeight="350"MinHeight="350"Width="525"MaxWidth="525"MinWidth="525"

  

????>

  

??

  

?????

  

????

  

??????

  

??????

  

??????

  

??????

  

??????

  

??????

  

????

  

????

  

??????

  

??????

  

??????

  

??????

  

????

  

????

  

????

常见问题解答/ Problem solution

深圳市基本医疗保险如何缴费
深圳社保局颁布了新的《深圳市社会医疗保险办法》,办法明确规定,基本医疗保险根据缴费及对应待遇分设一档、二档、三档三种形式。那么,深圳市基本医疗保险三个档次区别有哪些?主要是缴费、待遇和适用人群有所.........
深圳学位补贴,5月12日开始申报,非深户最高可领9000元
5月12日起,2020年深圳民办学校义务教育学位补贴,就要开始申报了!不管是深户还是非深户都可以申请!小学每人每年最多7000元(每学期最多3500元);初中每人每年最多9000元(每学期最多45.........
职称入深户
职称入深户(有区补贴的可以申请区补贴+市补贴,没有区补贴的只能申请市补贴)纯积分入户申请条件:第二步:进入后点击『市内移居』2、申请人户口簿服务处所栏反映申请人属党政机关(部、委、办、局)在编人员.........
深圳公积金拟出新规 广东省内或户籍地购房可提取公积金
11月30日,深圳市公积金中心对外发布《关于进一步规范我市住房公积金缴存提取等业务管理有关事项的通知(征求意见稿)》公开征求社会各界意见。据介绍,新规对原缴存、提取政策进行了补充和完善,主要包括明.........
深圳投靠入户相关规定流程详解
来源:深圳公安发布2016年9月1日起,《深圳市户籍迁入若干规定》正式实施,其中规范了非深户的部分亲属投靠深户亲属的实施细则与流程,下面就让我就来为大家详细梳理一下!老人投靠子女随迁入户1申请条件.........
聚焦烟台户籍改革:农村集体经济组织成员进城落户 依法取得的权益保持不变
新闻发布会现场烟台市农业农村局党组成员、副局长张刚大众网·海报新闻记者王艳蔡云飞烟台报道《烟台市人民政府关于深化户籍管理制度改革促进城乡融合区域协调发展的实施意见》将于10月10日起实行,9日,烟.........