All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
AJAX实例:根据邮编自动完成地址信息_[AJAX教程]
ASP.NET,MVC+LINQ开发一个图书销售站点(1)-需求分析_[Asp.Net教程]
总结:表单复选框向PHP传输数据的研究_php资料_编程技术
ASP.net,实现在线统计人数_[Asp.Net教程]
Asp.net日期字符串格式化显示方法_.net资料_编程技术
shopex4.8通用重写规则_php资料_编程技术
Asp.Net文件处理_[Asp.Net教程]
PHP和MYSQL制作动态网站开发经验之谈_php资料_编程技术
从各种位置截取字符串的SQL语法_[SQL Server教程]
SQL,Server,2005—有关开发的10个最重要的特点_[SQL,Server教程]
Reading number is top 10 pictures
有种屌丝级别的好妹子
Extremely rare TianShan Mountains snow lotus2
全球清廉国家排行
Fan bingbing black wings for platform and DanLuoWang believes beauty1
浴室里的美女
Absolutely shocked. National geographic 50 animal photographys10
毛俊杰-能量永动机
mythology hero1
西游四格漫画(四)
2013中国四川省高考作文
Download software ranking
网络管理员第三版
Ashlynn Video3
I'm come from Beijing1
实战黑客不求人
Sora aoi‘s film--Lust fan wall
SP4 for SQL2000
c#程序设计案例教程
Jinling thirteen stock
Such love down(擒爱记)
Tram sex maniac 2 (H) rar bag14
delv published in(发表于) 2014/1/10 6:29:30 Edit(编辑)
C#网络应用编程基础练习题与答案(五)_[Asp.Net教程]

C#网络应用编程基础练习题与答案(五)_[Asp.Net教程]

C#网络应用编程基础练习题与答案(五)_[Asp.Net教程]

1. 填空题

  1) 使控件是否可以对用户交互作出响应的属性是 Enabled 。


  2) 控制控件是否显示的属性是 Visible 。


  3) 若要在文本框中输入密码,常指定 PasswordChar 属性。


  4) 若某复选框某时刻CheckState属性的值为Indeterminate,则其属性Checked的值为 Unchecked 。


  5) 使用 Panel 或 GroupBox 控件可以将多个RadioButton控件分为两个单选组。


  6) 若不希望用户在ComboBox控件中编辑文本,则应将属性 DropDownStyle 的属性值设置为DropDownList。


  7) 用于设置MenuStrip控件中某菜单项快捷键的属性是 ShortcutKeys 。


  8) 用于控制ListView控件中的各项显示方式的属性是 View 。


  2. 判断题


  1) 控件就是属性、方法和事件的集合封装体。 ( 对 )


  2) TextBox控件只能用于单行文本的输入。 ( 错 )


  3) 通过RichTextBox控件只能够与RTF文件进行交互操作。 ( 错 )


  4) CheckBox控件的Checked属性与CheckState属性的值始终是相同的。 ( 错 )


  5) ToolTip组件用于显示某指定控件的自定义提示信息的。 ( 对 )


  3. 区别TextBox控件、MaskedTextBox控件、RichTextBox控件的使用场合。


  【解答】


  TextBox控件一般用于单段文本的编辑,可以设置为单行或多行的输入模式,也可以用作密码的输入;MaskedTextBox控件主要用于特定格式的单段文本编辑,在输入文本不符合格式要求的将会触发其MaskInputRejected事件;RichTextBox控件除了具有TextBox的一般文本编辑功能外,还可以进行多段文本的高级编辑功能,如改变文本、段落的显示格式、在文本中查找特定字符和字符串以及与Rtf文件的交互等。


  4. 简要说明CheckBox控件和RadioButton控件的区别。


  【解答】


  CheckBox控件可为用户提供选择功能,常用的是二选一的选择,如“真/假”或“是/否”;但该控件也可以通过属性的设置作三选一的选择。每一个CheckBox所代表的选择都是独立的,若有多个CheckBox控件构成一组选项时,则可以多个同时被选中,相互之间不影响,即复选。RadioButton控件,它与CheckBox控件功能类似,也是用于接收用户的选择,但它是以单项选择的形式出现,即一组RadioButton按钮中只能有一个处于选中状态。一旦某一项被选中,则同组中其他RadioButton按钮的选中状态自动清除。


  5. 设计一个Windows应用程序,窗体上有一个TextBox控件、一个Button控件。要求,每当用户单击按钮时,文本框都会增加一行文字来反映单击的次数,例如“第3次单击按钮”。


  【解答】


  1) 窗体界面如图Ex5-5-1所示;


C#网络应用编程基础练习题与答案(五)


  2) 窗体中主要控件属性设置如表Ex5-5-1;


表Ex5-5-1 窗体中的主要控件属性


控件


Name属性


功能


其它属性


TextBox控件


textBox1


显示信息


ScrollBars=Vertical; Multiline=True


Button控件


Button1


触发添加信息事件



Button2


触发结束添加事件


  3) 主要事件代码。


  ……
  int i = 1;
  bool Add = true;
  ……private void button1_Click(object sender, EventArgs e)
  {
  if(Add) textBox1.Text += "第" + i + "次单击按钮\r\n";
  i++;
  }
  private void button2_Click(object sender, EventArgs e)
  {
  Add = false;
  }


  6. 编写一段程序,向ListBox控件listBox1中,自动添加10个数,每个数占一项。


  【解答】


  主要代码如下:



  public partial class Form1 : Form
  {
  int m = 1;
  ……
  private void button1_Click(object sender, EventArgs e)
  {
  for (int i = m ; i < m+10; i++)
  {
  listBox1.Items.Add(i);
  }
  m = m + 10;
  }
  }


  7. 参照Windows系统“附件”中的“计算器”,自行编写一个简易的计算器。要求:可以实现由0~4构成的整数的加减运算。


  【解答】


  1) 窗体界面如图Ex5-5-2所示;


C#网络应用编程基础练习题与答案(五)


  2) 将InputNumber事件作为button0、button1、button2、button3、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 myCal = 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 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;
  }
  private 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 sender, EventArgs e)
  {
  textBox.Text = "";
  myCal = calculateType.none;
  isY = false;
  }
  }
  }


  8. 试利用TreeView、ListView等控件实现一个类似“资源管理器”的文档管理程序,用于查看C:\Documents and Settings目录下的文件。


  【解答】


  1) 新建一个名为WindowsControlsExercise的项目,在【解决方案资源管理器】中重命名文件Form1.cs为Explorer.cs,并设置Form1窗体的Text属性为“资源管理器”。


  2) 向窗体中添加一个SplitContainer控件、一个ImageList控件、一个TreeView控件、一个ListView控件,页面布局及各控件属性如图Ex5-5-3所示。


C#网络应用编程基础练习题与答案(五)


  3) 在【解决方案资源管理器】中,将imageList1控件中的两个图标文件添加到应用程序目录中,分别命名为folder.ico和doc.ico。


  4) 在Explorer.cs代码文件中添加命名空间:using System.IO,并添加构造函数代码如下:



  public Explorer()
  {
  InitializeComponent();
  PopulateTreeView();
  }
  private void PopulateTreeView()
  {
  TreeNode rootNode;
  DirectoryInfo info = new DirectoryInfo(@"C:\Documents and Settings");
  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 subDir 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中某个节点时,用该节点的内容来填充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 (DirectoryInfo 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.ListViewSubItem[]
  { new ListViewItem.ListViewSubItem(item, "File"),
  new ListViewItem.ListViewSubItem(item,
  file.LastAccessTime.ToShortDateString())};
  item.SubItems.AddRange(subItems);
  listView1.Items.Add(item);
  }
  listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
  }


  6) 按键编译并执行。







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.