资源描述:
《VSTO-for-excel入门基础知识》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、常用语法IF语句privatevoidbuttonl1Click(objectsender,EventArgse){inti;i=-25;〃-2147483648到2147483647,有符号32位整数if(i>0){McssagcBox.Show(i+"是正数");}elseif(i二二0){McssagcBox.Show(i+"是零”);}else{MessageBox.Show(i+"是负数");}//更多分Z使用Switch结构,类似selectcase}While语句privatevoidbutton1
2、2Click(objectsender,EventArgse)Iinti;i二0;while(i<10)//括号内条件成立,不断执行花括号内容{i=i+1;}this.buttonl4.Text二i.ToStringO;//}FOR语句privatevoidbuttonl3_Click(objectsender,EventArgse){inti;//;intsum=0;for(i=1;i<=10;i++)//i++自加的意思if(i<=5)//if(i<=5){break;}sum=sum+i;}else{bre
3、ak;//跳出FORB不再执行。}}this,button13.Text=sum.ToString();}FOR语句privatevoidbuttonl4_Click(objectsender,EventArgse){//inti;这句声明变量,作用于整个单机过程intsum=0;for(inti=1;i<=10;i++)//也可在FOR循环内部声明直接加变量int,只做用内部{if(i==6)//i等于6{continue;}//当1=6跳过不加,到7的吋候继续加,比55小于6//严格区分break和conti
4、nuc语句{sum=sum+i;}}this.buttonl3.Text=sum.ToString();}FOREach语句privatevoidbuttonl5_Click(objectsender,EventArgse){int[]arr={2,5,7};//声明数组。arrL0]=2arr[l]=5arr[2]=7〃方法1//foreach(intbinarr)//{//MessageBox.Show(b.ToString());//}〃方法2for(inti=0;i<=2;i卄)MessagcBox・Sh
5、ow(arr[i]・ToStringO);文件对话框privatevoidbuttonlClick(objectsender,EvenlArgse){this・openFileDialog1・ShowDialogO;this・tcxtBoxl.Text=this,opcnEileDialog1・Ei1eName;}添加按钮privatevoidbutton2_Click(objectsender,EventArgse){TextBoxtx=newTextBox();lx.Text="自动添加文本框";tx.Bac
6、kColor二Color.Cyan;tx.Left=50;tx.Top=150;this.Controls.Add(tx);)关闭窗体privatevoidbuttonlClick(objectsender,EventArgse)Ithis.Dispose();//关闭自己)定义变量privatevoidbuttonlO_Click(objectsender,EventArgse){strings="张三";buttonl4.Text二s;}窗体显示必须关闭privatevoidbutton8_Click(obj
7、ectsender,EvenlArgsc){Form2f2=newForm20;//类模块创建对象f2.ShowDialogO;//Dialog必须关闭窗体2,才能编辑窗体1显示或者隐藏控件privatevoidchcckBoxlChcckcclChangcd(objectsendor,EventArgsc){//if(this.checkBoxl.Checked==true)//{this.button8.Visible二true;//}//else//{//this.button8.Visible=false
8、;//}this,button8.Visible=this.checkBoxl.Checked;//筹同于以上几句话}触发dataGridView的CellClick事件privatevoiddataGridView1_CellClick(objectsender,DataGridViewCellEventArgse){stringno=dataGridView1.Row