Windows窗体程序开发实验报告_第1页
Windows窗体程序开发实验报告_第2页
Windows窗体程序开发实验报告_第3页
Windows窗体程序开发实验报告_第4页
免费预览已结束,剩余11页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精通 C#与.NET4.0 数据库开发实验报告实验题目: Windows 窗体程序的开发专业计算机科学与技术学生姓名班级学号教师指导单位日期教师评教师签名:年月日语成绩评定备注一、实验目的1. 学会在 Visual Studio 2010 中创建和运行窗体程序。2. 掌握 Windows 窗体的基本操作。3. 学会使用常用的 Windows 控件。4. 学会使用菜单和工具栏以及通用对话框。二、实验环境.NET 框架开发环境Visual Studio 2010三、实验内容例 5-1 、2:源代码:publicpartialclassForm1 :FormpublicForm1( )Initial

2、izeComponent( );privatevoid AddInputToLog(stringinput)this .tbLog.AppendText("rn"+ input);this.tbLog.ScrollToCaret( );privatevoid btnSubmit_Click(objectsender,EventArgs e)stringinput =this .tbInput.Text;this .AddInputToLog(input);this .tbInput.Clear( );例5-3、 4:源代码:publicpartialclassFrmMain

3、 :FormpublicFrmMain( )InitializeComponent( );privatevoid btnSetProp_Click(objectsender,EventArgs e)this .Text =" 测试对话框 " ;this .FormBorderStyle =FormBorderStyle .FixedDialog;this .BackColor =Color .Gray;this .WindowState =FormWindowState.Normal;this .MinimizeBox =false ;this .Height = 200;

4、this .Width = 400;this .TopMost =true ;privateFrmMain _CurrFrm = null ; private void btnCreate_Click(objectsender,EventArgs e)if ( this ._CurrFrm =null )this ._CurrFrm =new FrmMain( );this ._CurrFrm.Show( );elsethis ._CurrFrm.Activate( );privatevoid btnClose_Click(objectsender,EventArgs e)if( this .

5、_CurrFrm !=null )this ._CurrFrm.Close( );this ._CurrFrm =null ;privatevoid FrmMain_Load( objectsender,EventArgs e)例5-5:源代码:/ label1参数设置this.label1.AutoSize =true;this.label1.BackColor = System.Drawing.Color.Red;this.label1.Font =new System.Drawing.Font(" 楷体 _GB2312",12F, System.Drawing.Fon

6、tStyle.Regular,System.Drawing.GraphicsUnit.Point,( byte )(134);this.label1.ForeColor = System.Drawing.Color.White;this.label1.Location =new System.Drawing.Point(68, 43);this.label1.Name ="label1"this.label1.Size =new System.Drawing.Size(232, 16);this.label1.TabIndex = 0;this.label1.Text =&

7、quot; 红底白字 , 楷体 小四号 ,无边框"this.label1.Click +=new System. EventHandler( this .label1_Click);/ label2参数设置this.label2.AutoSize =true;this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;this.label2.Font =new System.Drawing.Font("幼圆" ,15F,System.Drawing.FontStyle.Bold,Sy

8、stem.Drawing.GraphicsUnit.Point,( byte )(134);this.label2.Location =new System.Drawing.Point(49, 79);this.label2.Name ="label2"this.label2.Size =new System.Drawing.Size(289, 22);this.label2.TabIndex = 1;this.label2.Text =" 幼圆 小三 粗体 , Single边框" ;this.label2.Click +=new System. Eve

9、ntHandler( this .label2_Click);例5-6:源代码:publicpartialclassForm1 :Formprivateint_Value = 0;/btnShowMsg 的Click 事件处理函数privatevoid btnShowMsg_Click( objectsender,EventArgs e)MessageBox.Show( string.Format( " 现在需要 : 0 ",this ._Value);/ “ 多一点 ”按钮 Click 事件处理函数privatevoid btnAdd_Click(objectsender

10、,EventArgs e)this ._Value+;this .lbRes.Text =string.Format( " 现在需要 : 0 ",this ._Value);/ “ 少一点 ”按钮 Click 事件处理函数privatevoid btnSub_Click(objectsender,EventArgs e)this ._Value-;this .lbRes.Text =string.Format( " 现在需要:0",this ._Value);例5-7:源代码:publicpartialclassForm1 :FormpublicForm

11、1( )InitializeComponent( );privatevoid buttons_CheckedChanged( objectsender,EventArgs e)stringweeks ="" ;weeks += ckbWeek1.Checked ?weeks += ckbWeek2.Checked ?weeks += ckbWeek3.Checked ?weeks += ckbWeek4.Checked ?weeks += ckbWeek5.Checked ?weeks += ckbWeek6.Checked ?weeks += ckbWeek7.Check

12、ed ?stringsport ="" ;sport += rbSword.Checked ?sport += rbJump.Checked ?sport += rbTiCao.Checked ?stringjiangpai ="" ;jiangpai += rbGold.Checked ?jiangpai += rbSliver.Checked ?jiangpai += rbTong.Checked ?" 星期一" : """ 星期二" : """ 星期三&quo

13、t; : """ 星期四" : """ 星期五" : """ 星期六" : """ 星期日" : """ 击剑": """ 跳水" : """ 体操": """ 金牌": """ 银牌" : """ 铜牌&qu

14、ot; : ""this .lbHint.Text = weeks + sport + jiangpai;例5-8:源代码:publicpartialclassForm1 :Formprivatevoid Form1_Load( objectsender,EventArgs e)/ 手机号码:13后面 9个必填数字this .mtbPhone.Mask ="quot; ;/ 电话: 4位必填区号,7或8位号码 ?this .tbName.Text ="" ;this .tbUsers.Text ="&quo

15、t; ;privatevoid btnAdd_Click(objectsender,EventArgs e)stringusr =string.Format( "<0>:<1>:<2>",this .tbName.Text,this .mtbPhone.Text,this .mtbMobile.Text);/ 产生用户信息/ 添加到用户记录文本框 ¨°this .tbUsers.AppendText(usr + System.this .mtbMobile.Text ="" ;this .mtbPh

16、one.Text ="" ;this .tbName.Text ="" ;Environment .NewLine);/ 清空用户信息例5-9:源代码:publicpartialclassForm1 :FormpublicForm1( )InitializeComponent( );privatevoid Form1_Load( objectsender,EventArgs e)/ 设置 cmbHouXuan只能从 ComboBox中的已有候选值选择this .cmbHouXuan.DropDownStyle =ComboBoxStyle.DropDow

17、nList;/lstResult只能执行单选,并且对所有值进行排序this .lstResults.SelectionMode =SelectionMode .One;this .lstResults.Sorted =true ;this .GenerateCombItems( );/ 产生 ComboBox中D的可选项privatevoid GenerateCombItems( )/ 移除原有的数据Randomrd =new Random();for ( inti = 0; i < 10; i+)/ 随机生成 10个新的数据stringitem =string.Format( &quo

18、t;Item-0:X8", rd.Next( );/ 添加到 ComboBox中this .cmbHouXuan.SelectedIndex = 0;/ 默认选中第一条/ 重新生成 ComboBox中的侯选项privatevoid btnFresh_Click(objectsender,EventArgs e)this .GenerateCombItems( );/ 重新生成 CombBox中的候选项/ 将 CombBox中选中值 | 添加到 ListBox 中Dprivatevoid btnAddOne_Click(objectsender,EventArgs e)/ 通过 Com

19、boBox.SelectedItem 获取当前选中的候选项,然后添加到ListBox中Dstringitem = (string) this .cmbHouXuan.SelectedItem;/ 从 ListBox 中移除当前选中项privatevoid btnRemoveOne_Click( objectsender,EventArgs e)if( this .lstResults.SelectedIndex >= 0)/ 如果当前 ListBox 中有选中条目,移除它this .lstResults.SelectedIndex);/ 从 ListBox 中移除所有项privatevo

20、id btnRemovAll_Click(objectsender,EventArgs e)例5-10 :源代码:privatevoid btnMsgBox_Click(objectsender,EventArgs e)MessageBox.Show( " 这是第一个消息框,只有确认按钮" );/ 显示最简单的 MessageBoxMessageBox.Show( " 这是二个消息框 ¨,有标题,只有确认按钮" ," 第二个消息框 " );/ 显示有文本和标题的 MessageBox/ 显示具有文本、标题、确定和取消按钮的

21、MessageBoxMessageBox.Show( " 这是第三个消息框¨ ,有标题,只有确认和¨取消按钮 " ," 第三个消息框 " , MessageBoxButtons .OKCancel);/ 显示具有文本、标题、确定和 ¨取消按钮、告警图标的 MessageBoxMessageBox.Show( " 这是第四个消息框¨ ,有标题,只有确认和取消按钮,告警图标" ," 第四个消息框 " , MessageBoxButtons .OKCancel ,MessageBo

22、xIcon. Warning);例5-11 :源代码:private void btnOpenFile_Click(object sender, EventArgs e)OpenFileDialog ofdlg = new OpenFileDialog( );/ 创建 OpenFileDialog 对象ofdlg.Filter = "文本文件 (*.txt)|*.TXT|Word文件 (*.doc)|*.DOC" /只选择 TXT和DOC扩展名文件ofdlg.Title = "选择文本文件或 Word文件 "/设置对话框的标题if(ofdlg.ShowDialo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论