控件使用实验报告_第1页
控件使用实验报告_第2页
控件使用实验报告_第3页
控件使用实验报告_第4页
控件使用实验报告_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

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

文档简介

1、实验报告课程名称面向对象程序设计实验名称实验五、控件使用日期学生学号姓名班级实验目的:1掌握窗体的常用属性的使用。2. 掌握文本操作类控件中的标签控件和文本控件的使用。3掌握选择操作类控件中的复选框、单选框、列表框、组合框的使用。实验要求:1.认真阅读、掌握和本实验相关的教材内容。2.设计并编写代码完成题目要求的任务。3.撰写实验报告。实验内容与步骤:1.多窗体练习实现如图所示功能。输入用户名后点击登录按钮,弹出右图消息框。要求在消息框中显示用户输入的用户名和“欢迎你”语句。点击取消按钮结束程序运行。源代码: 在窗体form1里面添加如下代码:using System;using System

2、.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace shiyan5 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) Mess

3、ageBox.Show(this.textBox1.Text+欢?迎-你?!?,提示?消?息,MessageBoxButtons.OK,MessageBoxIcon.Information); private void button2_Click(object sender, EventArgs e) this.Close(); 2.文本框,标签和按钮练习实现如图所示功能。点击红色按钮,将文本框中的文字颜色变成红色,同时把该按钮变成不可用(提示:修改按钮的Enabled属性为false使其不可用);点击黑色按钮,将文本框中的文字颜色变成黑色,同时把该按钮变成不可用;点击“文本内容复制到标签”将

4、文本框内容复制到下方标签。源代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace shiyan5_2 public partial class Form1 : Form public Form1() InitializeComponent(); private void b

5、utton1_Click(object sender, EventArgs e) textBox1.ForeColor = System.Drawing.Color.Red; this.button1.Enabled=false; private void button2_Click(object sender, EventArgs e) textBox1.ForeColor = System.Drawing.Color.Black; this.button2.Enabled = false; private void button3_Click(object sender, EventArg

6、s e) label1.Text = textBox1.Text; 3定时器练习在窗体中显示字符,每隔1秒字符移动一定距离,先右移,移到右边界,再左移,移到左边界,又一次右移,如此循环。(提示:修改标签的Left属性值) 源代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespac

7、e shiyan5_3 public partial class Form1 : Form public Form1() InitializeComponent(); private bool MoveToRight = true; private void timer1_Tick(object sender, EventArgs e) int x = label1.Location.X; int y = label1.Location.Y; int increment = 10; if (MoveToRight) if (x + label1.Size.Width) + increment

8、= this.ClientRectangle.Width) MoveToRight = false; else label1.Location = new Point(x + increment, y); if (!MoveToRight) if (x - increment = 0) MoveToRight = true; else label1.Location = new Point(x - increment, y); 4复选框、单选框、组合框练习实现如图所示的功能。要求对相应控件做了设置之后,马上见到对应的字体效果。清除按钮用来清除文本框中的文字内容,退出按钮用来退出程序。源代码:

9、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace shiyan5_4 public partial class Form1 : Form public Form1() InitializeComponent(); private void button2_Click(objec

10、t sender, EventArgs e) this.Close(); private void button1_Click(object sender, EventArgs e) textBox1.Text = ; private void radioButton1_CheckedChanged(object sender, EventArgs e) textBox1.Font = new System.Drawing.Font(宋?体?,15f); private void radioButton2_CheckedChanged(object sender, EventArgs e) t

11、extBox1.Font = new System.Drawing.Font(楷?体?, 15f); private void radioButton4_CheckedChanged(object sender, EventArgs e) textBox1.Font = new System.Drawing.Font(黑体?, 15f); private void radioButton3_CheckedChanged(object sender, EventArgs e) textBox1.Font = new System.Drawing.Font(隶书, 15f); private vo

12、id checkBox1_CheckedChanged(object sender, EventArgs e) if (checkBox1.Checked) textBox1.Font = new Font(宋?体?,15f,FontStyle.Bold); private void checkBox2_CheckedChanged(object sender, EventArgs e) if (checkBox2.Checked) textBox1.Font = new Font(宋?体?, 15f, FontStyle.Italic); private void checkBox3_Che

13、ckedChanged(object sender, EventArgs e) if (checkBox3.Checked) textBox1.Font = new Font(宋?体?, 15f, FontStyle.Underline); private void checkBox4_CheckedChanged(object sender, EventArgs e) if (checkBox4.Checked) textBox1.Font = new Font(宋?体?, 15f, FontStyle.Strikeout); private void comboBox1_SelectedI

14、ndexChanged(object sender, EventArgs e) comboBox1.SelectedItem = new Font(宋?体?,textBox1.Font.Size); 5列表框练习实现程序如下功能:在文本框中输入水果,点击添加按钮将输入的水果添加到列表框中,如果列表框中已存在此种水果则不添加;在列表框中选中某些水果后点击删除,删除这些果;点击清除按钮将列表框中的所有水果都清除。源代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Da

15、ta;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace shiyan5_5 public partial class TestList : Form public TestList() InitializeComponent(); private void AddButton_Click(object sender, EventArgs e) bool repeatJudege=false; if (textBox.Text.Trim() != ) fore

16、ach (string item in FruitListBox.Items) if (textBox.Text = item) MessageBox.Show(列表已有 + textBox.Text, 错误提醒, MessageBoxButtons.OK, MessageBoxIcon.Error); repeatJudege = true; break; if (!repeatJudege) FruitListBox.Items.Add(textBox.Text.Trim(); textBox.Text = ; else MessageBox.Show(输入不能为空值, 错误提醒, Mes

17、sageBoxButtons.OK, MessageBoxIcon.Error); private void DelButton_Click(object sender, EventArgs e) int count=FruitListBox.SelectedItems.Count; if (count != 0) for (int i = 0; i count; i+) FruitListBox.Items.Remove(FruitListBox.SelectedItems0); else MessageBox.Show(请选中删除项, 错误提醒, MessageBoxButtons.OK,

18、 MessageBoxIcon.Error); private void DelAllButton_Click(object sender, EventArgs e) if (FruitListBox.Items.Count!=0) FruitListBox.Items.Clear(); else MessageBox.Show(表中为空, 错误提醒, MessageBoxButtons.OK, MessageBoxIcon.Error); private void TestList_Load(object sender, EventArgs e) 6. 简单记事本。使用菜单方式实现字体选择和

19、文字颜色的选择;使用工具栏方式实现字体选择和文字颜色的选择;使用状态栏显示当前输入的文字的个数信息。源代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace shiyan5_6 public partial class Form1 : Form public Form1()

20、InitializeComponent(); private void 字体选择ToolStripMenuItem_Click(object sender, EventArgs e) FontDialog fd = new FontDialog(); if (fd.ShowDialog() = DialogResult.OK) textBox1.Font = fd.Font; private void Form1_Load(object sender, EventArgs e) toolStripStatusLabel2.Text = 0; private void toolStripButt

21、on1_Click(object sender, EventArgs e) FontDialog fd = new FontDialog(); if (fd.ShowDialog() = DialogResult.OK) textBox1.Font = fd.Font; private void 则提示颜色ToolStripMenuItem_Click(object sender, EventArgs e) ColorDialog fd = new ColorDialog(); if (fd.ShowDialog() = DialogResult.OK) textBox1.ForeColor

22、= fd.Color; private void toolStripButton2_Click(object sender, EventArgs e) ColorDialog fd = new ColorDialog(); if (fd.ShowDialog() = DialogResult.OK) textBox1.ForeColor = fd.Color; private void textBox1_TextChanged(object sender, EventArgs e) toolStripStatusLabel2.Text = textBox1.Text.Length.ToString(); 7. 简单图片查看器。要求使用PictureBox和ImageList控件。源代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace shiyan5_7 public partial class Form1 : Form public Form1() Ini

温馨提示

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

评论

0/150

提交评论