C網(wǎng)絡(luò)應(yīng)用編程基礎(chǔ) 習(xí)題解答_第1頁
C網(wǎng)絡(luò)應(yīng)用編程基礎(chǔ) 習(xí)題解答_第2頁
C網(wǎng)絡(luò)應(yīng)用編程基礎(chǔ) 習(xí)題解答_第3頁
C網(wǎng)絡(luò)應(yīng)用編程基礎(chǔ) 習(xí)題解答_第4頁
C網(wǎng)絡(luò)應(yīng)用編程基礎(chǔ) 習(xí)題解答_第5頁
已閱讀5頁,還剩1頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、習(xí)題5參考解答1. 填空題 1) 使控件是否可以對用戶交互作出響應(yīng)的屬性是 Enabled 。 2) 控制控件是否顯示的屬性是 Visible 。 3) 若要在文本框中輸入密碼,常指定 PasswordChar 屬性。 4) 若某復(fù)選框某時刻CheckState屬性的值為Indeterminate,則其屬性Checked的值為 Unchecked 。 5) 使用 Panel 或 GroupBox 控件可以將多個RadioButton控件分為兩個單選組。 6) 若不希望用戶在ComboBox控件中編輯文本,則應(yīng)將屬性 DropDownStyle 的屬性值設(shè)置為DropDownList。 7) 用

2、于設(shè)置MenuStrip控件中某菜單項快捷鍵的屬性是 ShortcutKeys 。 8) 用于控制ListView控件中的各項顯示方式的屬性是 View 。2. 判斷題 1) 控件就是屬性、方法和事件的集合封裝體。( 對 ) 2) TextBox控件只能用于單行文本的輸入。( 錯 ) 3) 通過RichTextBox控件只能夠與RTF文件進行交互操作。( 錯 ) 4) CheckBox控件的Checked屬性與CheckState屬性的值始終是相同的。( 錯 ) 5) ToolTip組件用于顯示某指定控件的自定義提示信息的。( 對 )3. 區(qū)別TextBox控件、MaskedTextBox控件

3、、RichTextBox控件的使用場合?!窘獯稹縏extBox控件一般用于單段文本的編輯,可以設(shè)置為單行或多行的輸入模式,也可以用作密碼的輸入;MaskedTextBox控件主要用于特定格式的單段文本編輯,在輸入文本不符合格式要求的將會觸發(fā)其MaskInputRejected事件;RichTextBox控件除了具有TextBox的一般文本編輯功能外,還可以進行多段文本的高級編輯功能,如改變文本、段落的顯示格式、在文本中查找特定字符和字符串以及與Rtf文件的交互等。4. 簡要說明CheckBox控件和RadioButton控件的區(qū)別。【解答】CheckBox控件可為用戶提供選擇功能,常用的是二選

4、一的選擇,如“真/假”或“是/否”;但該控件也可以通過屬性的設(shè)置作三選一的選擇。每一個CheckBox所代表的選擇都是獨立的,若有多個CheckBox控件構(gòu)成一組選項時,則可以多個同時被選中,相互之間不影響,即復(fù)選。RadioButton控件,它與CheckBox控件功能類似,也是用于接收用戶的選擇,但它是以單項選擇的形式出現(xiàn),即一組RadioButton按鈕中只能有一個處于選中狀態(tài)。一旦某一項被選中,則同組中其他RadioButton按鈕的選中狀態(tài)自動清除。5. 設(shè)計一個Windows應(yīng)用程序,窗體上有一個TextBox控件、一個Button控件。要求,每當(dāng)用戶單擊按鈕時,文本框都會增加一行

5、文字來反映單擊的次數(shù),例如“第3次單擊按鈕”。【解答】 1) 窗體界面如圖Ex5-5-1所示; 2) 窗體中主要控件屬性設(shè)置如表Ex5-5-1;表Ex5-5-1 窗體中的主要控件屬性控件Name屬性功能其它屬性TextBox控件textBox1顯示信息ScrollBars=Vertical; Multiline=TrueButton控件Button1觸發(fā)添加信息事件Button2觸發(fā)結(jié)束添加事件圖Ex5-5-1 窗體界面 3) 主要事件代碼。int i = 1;bool Add = true;private void button1_Click(object sender, EventArgs

6、 e) if(Add) textBox1.Text += "第" + i + "次單擊按鈕rn" i+;private void button2_Click(object sender, EventArgs e) Add = false;6. 編寫一段程序,向ListBox控件listBox1中,自動添加10個數(shù),每個數(shù)占一項。【解答】 主要代碼如下。public partial class Form1 : Form int m = 1; private void button1_Click(object sender, EventArgs e) for

7、 (int i = m ; i < m+10; i+) listBox1.Items.Add(i); m = m + 10; 7. 參照Windows系統(tǒng)“附件”中的“計算器”,自行編寫一個簡易的計算器。要求:可以實現(xiàn)由04構(gòu)成的整數(shù)的加減運算?!窘獯稹?1) 窗體界面如圖Ex5-5-2所示;button0、button1、button2、button3、button4、buttonClear、buttonEqual、buttonAdd、buttonSubtextBox圖Ex5-5-2 窗體界面 2) 將InputNumber事件作為button0、button1、button2、but

8、ton3、button4的Click事件。 完整代碼如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Exer2 public partial class FormCalculator : Form enum calculateType none, add, sub ; calculateType myCa

9、l = calculateType.none; int x, y; bool isY = false; public FormCalculator() InitializeComponent(); textBox.TextAlign = HorizontalAlignment.Right; private void InputNumber(object sender, EventArgs e) Button num = (Button)sender; if (isY) textBox.Clear(); isY = false; textBox.Text += num.Text; private

10、 void buttonEqual_Click(object sender, EventArgs e) y = Convert.ToInt32(textBox.Text); if (myCal = calculateType.add) textBox.Text = Convert.ToString(x + y); myCal = calculateType.none; if (myCal = calculateType.sub) textBox.Text = Convert.ToString(x - y); myCal = calculateType.none; isY = true; pri

11、vate void addButton_Click(object sender, EventArgs e) myCal = calculateType.add; x = Convert.ToInt32(textBox.Text); isY = true; private void buttonSub_Click(object sender, EventArgs e) myCal = calculateType.sub; x = Convert.ToInt32(textBox.Text); isY = true; private void buttonClear_Click(object sen

12、der, EventArgs e) textBox.Text = "" myCal = calculateType.none; isY = false; 8. 試利用TreeView、ListView等控件實現(xiàn)一個類似“資源管理器”的文檔管理程序,用于查看C:Documents and Settings目錄下的文件。【解答】 1) 新建一個名為WindowsControlsExercise的項目,在【解決方案資源管理器】中重命名文件Form1.cs為Explorer.cs,并設(shè)置Form1窗體的Text屬性為“資源管理器”。 2) 向窗體中添加一個SplitContaine

13、r控件、一個ImageList控件、一個TreeView控件、一個ListView控件,頁面布局及各控件屬性如圖Ex5-5-3所示。treeView1Dock:FillImageList:imageList1imageList1Images: 添加兩個圖標(biāo),分別用于指示文件夾和文件splitContainer1Dock:FilllistView1Dock:FillView:DetailsSmallImageList:imageList1Columns:添加三列,分別設(shè)置Text屬性為Name、Type、Last Modified圖Ex5-5-3 “資源管理器”設(shè)計界面 3) 在【解決方案資源管

14、理器】中,將imageList1控件中的兩個圖標(biāo)文件添加到應(yīng)用程序目錄中,分別命名為folder.ico和doc.ico。 4) 在Explorer.cs代碼文件中添加命名空間:using System.IO,并添加構(gòu)造函數(shù)代碼如下:public Explorer() InitializeComponent(); PopulateTreeView();private void PopulateTreeView() TreeNode rootNode; DirectoryInfo info = new DirectoryInfo("C:Documents and Settings&qu

15、ot;); if (info.Exists) rootNode = new TreeNode(info.Name); rootNode.Tag = info; GetDirectories(info.GetDirectories(), rootNode); treeView1.Nodes.Add(rootNode); private void GetDirectories(DirectoryInfo subDirs, TreeNode nodeToAddTo) TreeNode aNode; DirectoryInfo subSubDirs; foreach (DirectoryInfo su

16、bDir in subDirs) aNode = new TreeNode(subDir.Name, 0, 0); aNode.Tag = subDir; aNode.ImageKey = "folder" subSubDirs = subDir.GetDirectories(); if (subSubDirs.Length != 0) GetDirectories(subSubDirs, aNode); nodeToAddTo.Nodes.Add(aNode); 5) 添加treeView1的NodeMouseClick事件,使單擊treeView1中某個節(jié)點時,用該節(jié)點

17、的內(nèi)容來填充listView1。private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) TreeNode newSelected = e.Node; listView1.Items.Clear(); DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag; ListViewItem.ListViewSubItem subItems; ListViewItem item = null; foreach (DirectoryI

18、nfo dir in nodeDirInfo.GetDirectories() item = new ListViewItem(dir.Name, 0); subItems = new ListViewItem.ListViewSubItem new ListViewItem.ListViewSubItem(item, "Directory"), new ListViewItem.ListViewSubItem(item, dir.LastAccessTime.ToShortDateString(); item.SubItems.AddRange(subItems); listView1.Items.Add(item); foreach (FileInfo file in nodeDirInfo.GetFiles() item = new ListViewItem(file.Name, 1); subItems = new ListViewItem.ListViewSubIt

溫馨提示

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

評論

0/150

提交評論