




免费预览已结束,剩余10页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
精通C#与.NET4.0数据库开发实验报告实验题目:Windows窗体程序的开发专 业 计算机科学与技术 学 生 姓 名 班 级 学 号 教 师 指 导 单 位 日 期 教师评语 教师签名: 年 月 日成绩评定备 注一、实验目的1. 学会在Visual Studio 2010中创建和运行窗体程序。2. 掌握Windows窗体的基本操作。3. 学会使用常用的Windows控件。4. 学会使用菜单和工具栏以及通用对话框。二、实验环境.NET框架开发环境 Visual Studio 2010三、实验内容例5-1、2:源代码: public partial class Form1 : Form public Form1( ) InitializeComponent( ); private void AddInputToLog(string input) this.tbLog.AppendText(rn + input); this.tbLog.ScrollToCaret( ); private void btnSubmit_Click(object sender, EventArgs e) string input = this.tbInput.Text; this.AddInputToLog(input); this.tbInput.Clear( ); 例5-3、4: 源代码:public partial class FrmMain : Form public FrmMain( ) InitializeComponent( ); private void btnSetProp_Click(object sender, EventArgs e) this.Text = 测试对话框; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.BackColor = Color.Gray; this.WindowState = FormWindowState.Normal; this.MinimizeBox = false; this.Height = 200; this.Width = 400; this.TopMost = true; private FrmMain _CurrFrm = null; private void btnCreate_Click(object sender, EventArgs e) if(this._CurrFrm = null) this._CurrFrm = new FrmMain( ); this._CurrFrm.Show( ); else this._CurrFrm.Activate( ); private void btnClose_Click(object sender, EventArgs e) if (this._CurrFrm != null) this._CurrFrm.Close( ); this._CurrFrm = null; private void FrmMain_Load(object sender, 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.FontStyle.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 = 红底白字,楷体 小四号, 无边框; 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, System.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.EventHandler(this.label2_Click);例5-6: 源代码:public partial class Form1 : Form private int _Value = 0; /btnShowMsg的Click事件处理函数 private void btnShowMsg_Click(object sender, EventArgs e) MessageBox.Show(string.Format(现在需要: 0 , this._Value); /“多一点”按钮Click事件处理函数 private void btnAdd_Click(object sender, EventArgs e) this._Value+; this.lbRes.Text = string.Format(现在需要: 0 , this._Value); /“少一点”按钮Click事件处理函数 private void btnSub_Click(object sender, EventArgs e) this._Value-; this.lbRes.Text = string.Format(现在需要: 0 , this._Value); 例5-7:源代码:public partial class Form1 : Form public Form1( ) InitializeComponent( ); private void buttons_CheckedChanged(object sender, EventArgs e) string weeks = ; weeks += ckbWeek1.Checked ? 星期一 : ; weeks += ckbWeek2.Checked ? 星期二 : ; weeks += ckbWeek3.Checked ? 星期三 : ; weeks += ckbWeek4.Checked ? 星期四 : ; weeks += ckbWeek5.Checked ? 星期五 : ; weeks += ckbWeek6.Checked ? 星期六 : ; weeks += ckbWeek7.Checked ? 星期日 : ; string sport = ; sport += rbSword.Checked ? 击剑 : ; sport += rbJump.Checked ? 跳水 : ; sport += rbTiCao.Checked ? 体操 : ; string jiangpai = ; jiangpai += rbGold.Checked ? 金牌 : ; jiangpai += rbSliver.Checked ? 银牌 : ; jiangpai += rbTong.Checked ? 铜牌 : ; this.lbHint.Text = weeks + sport + jiangpai; 例5-8:源代码:public partial class Form1 : Form private void Form1_Load(object sender, EventArgs e) this.mtbMobile.Mask = /手机号码:13后面9个必填数字 this.mtbPhone.Mask = /电话:4位必填区号,7或8位号码? this.tbName.Text = ; this.tbUsers.Text = ; private void btnAdd_Click(object sender, EventArgs e) string usr = string.Format(:, /产生用户信息 this.tbName.Text, this.mtbPhone.Text, this.mtbMobile.Text); /添加到用户记录文本框 this.tbUsers.AppendText(usr + System.Environment.NewLine); this.mtbMobile.Text = ; /清空用户信息 this.mtbPhone.Text = ; this.tbName.Text = ; 例5-9:源代码:public partial class Form1 : Form public Form1( ) InitializeComponent( ); private void Form1_Load(object sender, EventArgs e) /设置cmbHouXuan只能从ComboBox中的已有候选值选择 this.cmbHouXuan.DropDownStyle = ComboBoxStyle.DropDownList; /lstResult只能执行单选,并且对所有值进行排序 this.lstResults.SelectionMode = SelectionMode.One; this.lstResults.Sorted = true; this.GenerateCombItems( ); /产生ComboBox中D的可选项 private void GenerateCombItems( ) this.cmbHouXuan.Items.Clear( ); /移除原有的数据 Random rd = new Random(); for (int i = 0; i = 0) /如果当前ListBox中有选中条目,移除它 this.lstResults.Items.RemoveAt(this.lstResults.SelectedIndex); /从ListBox中移除所有项 private void btnRemovAll_Click(object sender, EventArgs e) this.lstResults.Items.Clear( ); 例5-10: 源代码:private void btnMsgBox_Click(object sender, EventArgs e) MessageBox.Show(这是第一个消息框,只有确认按钮); /显示最简单的MessageBox MessageBox.Show(这是二个消息框,有标题,只有确认按钮, 第二个消息框); /显示有文本和标题的MessageBox/显示具有文本、标题、确定和取消按钮的MessageBox MessageBox.Show(这是第三个消息框,有标题,只有确认和取消按钮, 第三个消息框, MessageBoxButtons.OKCancel); /显示具有文本、标题、确定和取消按钮、告警图标的MessageBox MessageBox.Show(这是第四个消息框,有标题,只有确认和取消按钮,告警图标, 第四个消息框, MessageBoxButtons.OKCancel,MessageBoxIcon.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.ShowDialog() = DialogResult.OK) /显示对话框,并等待返回 this.tbOpenFileName.Text = ofdlg.FileName; /如果用户选择了文件则显示到界面 else this.tbOpenFileName.Text = 还没有选择要打开的文件; /没有选择文件,则显示默认提示 例5-12:源代码:private void btnSetColor_Click(object sender, EventAr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论