Windows桌面应用程序开发.ppt
privatevoidbutton1_Click(objectsender,EventArgse){try{doublea1=double.Parse(textBox1.Text);doublea2=double.Parse(textBox2.Text);doublea3=0;if(comboBox1.Text.ToString()==+){a3=a1+a2;}if(comboBox1.Text.ToString()==-){a3=a1-a2;}if(comboBox1.Text.ToString()==*){a3=a1*a2;}if(comboBox1.Text.ToString()==/){a3=a1/a2;}textBox3.Text=a3.ToString();}catch(Exceptionex){MessageBox.Show(ex.ToString());}}组件应用Timer组件应用ImageList组件应用Timer组件Timer是定期引发事件的组件,该组件是为Windows窗体环境设计的。属性Enable属性:指定计时器是否运行。Interval属性:获取或设置引发Elapsed事件的间隔。方法Change方法:更改计时器的启动时间和方法调用之间的间隔。ToString方法:返回当前Object的String。事件Tick事件:当指定的计时器间隔已过去而且计时器处于启用状态时发生。Elapsed事件:到达间隔时发生。privatevoidtimer1_Tick(objectsender,EventArgse){button1.Enabled=false;}privatevoidForm1_Load(objectsender,EventArgse){this.timer1.Interval=1000;this.timer1.Enabled=true;}privatevoidtimer1_Tick(objectsender,EventArgse){label1.Text=“当前时间:”+();}应用ImageList组件功能用于存储图像,这些图像随后可由控件显示。属性Images属性:表示图像列表中包含图像的集合。方法Draw方法:主要用于绘制指示的图像。privatevoidbutton1_Click(objectsender,EventArgse){this.pictureBox1.Image=imageList1.Images[0];this.pictureBox2.Image=imageList1.Images[1];}其他常用控件应用ListView控件应用TreeView控件应用PictureBox控件privatevoidForm1_Load(objectsender,EventArgse){richTextBox1.SelectionFont=newFon