Windows窗體程序的開發(fā)實驗報告.doc_第1頁
Windows窗體程序的開發(fā)實驗報告.doc_第2頁
Windows窗體程序的開發(fā)實驗報告.doc_第3頁
Windows窗體程序的開發(fā)實驗報告.doc_第4頁
Windows窗體程序的開發(fā)實驗報告.doc_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

精品文檔精通C#與.NET4.0數(shù)據(jù)庫開發(fā)實驗報告實驗題目:Windows窗體程序的開發(fā)專 業(yè) 計算機科學與技術(shù) 學 生 姓 名 班 級 學 號 教 師 指 導 單 位 日 期 教師評語 教師簽名: 年 月 日成績評定備 注一、實驗目的1. 學會在Visual Studio 2010中創(chuàng)建和運行窗體程序。2. 掌握Windows窗體的基本操作。3. 學會使用常用的Windows控件。4. 學會使用菜單和工具欄以及通用對話框。二、實驗環(huán)境.NET框架開發(fā)環(huán)境 Visual Studio 2010三、實驗內(nèi)容例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參數(shù)設(shè)置 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參數(shù)設(shè)置 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事件處理函數(shù) private void btnShowMsg_Click(object sender, EventArgs e) MessageBox.Show(string.Format(現(xiàn)在需要: 0 , this._Value); /“多一點”按鈕Click事件處理函數(shù) private void btnAdd_Click(object sender, EventArgs e) this._Value+; this.lbRes.Text = string.Format(現(xiàn)在需要: 0 , this._Value); /“少一點”按鈕Click事件處理函數(shù) private void btnSub_Click(object sender, EventArgs e) this._Value-; this.lbRes.Text = string.Format(現(xiàn)在需要: 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個必填數(shù)字 this.mtbPhone.Mask = /電話:4位必填區(qū)號,7或8位號碼? this.tbName.Text = ; this.tbUsers.Text = ; private void btnAdd_Click(object sender, EventArgs e) string usr = string.Format(:, /產(chǎn)生用戶信息 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) /設(shè)置cmbHouXuan只能從ComboBox中的已有候選值選擇 this.cmbHouXuan.DropDownStyle = ComboBoxStyle.DropDownList; /lstResult只能執(zhí)行單選,并且對所有值進行排序 this.lstResults.SelectionMode = SelectionMode.One; this.lstResults.Sorted = true; this.GenerateCombItems( ); /產(chǎn)生ComboBox中D的可選項 private void GenerateCombItems( ) this.cmbHouXuan.Items.Clear( ); /移除原有的數(shù)據(jù) 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( ); /創(chuàng)建OpenFileDialog對象 ofdlg.Filter = 文本文件(*.txt)|*.TXT|Word文件(*.doc)|*.DOC; /只選擇TXT和DOC擴展名文件 ofdlg.Title = 選擇文本文件或Word文件; /設(shè)置對話框的標題 if(ofdlg.ShowDialog() = DialogResult.OK) /顯示對話框,并等待返回 this.tbOpenFileName.Text = ofdlg.FileName; /如果用戶選擇了文件則顯示到界面 else this.tbOpenFileName.Text = 還沒有選擇要打開的文件; /沒有選擇文件,則顯示默認提示 例5-12:源代碼:private void btnSetColor_Click(object sender, EventArgs e) ColorDialog cdlg = new ColorDialog( ); /創(chuàng)建Co

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論