实训三Windows应用程序开发一、实验目的1.掌握窗口控件的使用方法;2.掌握Windows的编程基础。二、实验要求根据要求,编写C#程序,并将程序代码和运行结果写入实验报告。三、实验内容1.编写一个计算器,练习在窗体上添加控件、调整控件的布局,设置或修改控件属性,编写事件处理程序的方法。(1)新建windows应用程序。在窗体Form上拖放一个TextBox控件、十六个Button控件,整个窗体布局如下图所示在计算器中,增加四个功能键:x2,sqrt,log,ln四个键,分别计算求平方,开方,log,ln值,将增加的代码写入实验报告。2.自己编写一个Windows应用程序,使用4~5个公共控件。将程序功能、界面布局和运行结果的截图与事件代码写在实验报告中。第一题代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacecalculator{publicpartialclassForm1:Form{doublea=0;doubleb=0;boolc=false;stringd;publicForm1(){InitializeComponent();}publicvoidForm1_Load(objectsender,EventArgse){}privatevoidbutton9_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=1;}privatevoidbutton10_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=2;}privatevoidbutton11_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=3;}privatevoidbutton5_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=4;}privatevoidbutton6_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=5;}privatevoidbutton7_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=6;}privatevoidbutton1_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=7;}privatevoidbutton2_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=8;}privatevoidbutton3_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=9;}privatevoidbutton13_Click(objectsender,EventArgse){if(c==true){textBox1.Text=;c=false;}textBox1.Text+=0;if(d==/){textBox1.Clear();MessageBox.Show(除数不能为零,错误提示,MessageBoxButtons.OK,MessageBoxIcon.Warning);}}privatevoidbutton15_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);d=+;}privatevoidbutton12_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);d=-;}privatevoidbutton8_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);d=*;}privatevoidbutton4_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);d=/;}privatevoidbutton16_Click(objectsender,EventArgse){switch(d){case+:a=b+double.Parse(textBox1.Text);break;case-:a=b-double.Parse(textBox1.Text);break;case*:a=b*double.Parse(textBox1.Text);break;case/:a=b/double.Parse(textBox1.Text);break;}textBox1.Text=a+;c=true;}privatevoidbutton14_Click(objectsender,EventArgse){textBox1.Text=;}privatevoidbutton17_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);a=Math.Pow(b,2);textBox1.Text=a+;}privatevoidbutton18_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);a=Math.Sqrt(b);textBox1.Text=a+;}privatevoidbutton19_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);a=Math.Log10(b);textBox1.Text=a+;}privatevoidbutton20_Click(objectsender,EventArgse){c=true;b=double.Parse(textBox1.Text);a=Math.Log(b);textBox1.Text=a+;}}}运行结果:第二题代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacet2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidcheckBox1_CheckedChanged(objectsender,EventArgse){}privatevoid用®?户¡ì名?_TextChanged(objectsender,EventArgse){}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidlistBox1_SelectedIndexChanged(objectsender,EventArgse){}privatevoidtextBox1_TextChanged(objectsender,EventArgse){}privatevoidcheckBox2_CheckedChanged(objectsender,EventArgse){}privatevoidlabel1_Click(objectsender,EventArgse){}privatevoidtextBox1_TextChanged_1(objectsender,EventArgse){}privatevoidlabel2_Click(objectsender,EventArgse){}}}运行结果: