控件使用 实验报告Word格式文档下载.docx

上传人:b****1 文档编号:4211013 上传时间:2023-05-03 格式:DOCX 页数:15 大小:264.24KB
下载 相关 举报
控件使用 实验报告Word格式文档下载.docx_第1页
第1页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第2页
第2页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第3页
第3页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第4页
第4页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第5页
第5页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第6页
第6页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第7页
第7页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第8页
第8页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第9页
第9页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第10页
第10页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第11页
第11页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第12页
第12页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第13页
第13页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第14页
第14页 / 共15页
控件使用 实验报告Word格式文档下载.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

控件使用 实验报告Word格式文档下载.docx

《控件使用 实验报告Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《控件使用 实验报告Word格式文档下载.docx(15页珍藏版)》请在冰点文库上搜索。

控件使用 实验报告Word格式文档下载.docx

点击取消按钮结束程序运行。

源代码:

在窗体form1里面添加如下代码:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceshiyan5

{

publicpartialclassForm1:

Form

{

publicForm1()

InitializeComponent();

}

privatevoidbutton1_Click(objectsender,EventArgse)

MessageBox.Show(this.textBox1.Text+"

欢?

迎®

-你?

ê

?

"

"

提¬

¨

¢

示º

消?

息¡

é

MessageBoxButtons.OK,MessageBoxIcon.Information);

privatevoidbutton2_Click(objectsender,EventArgse)

this.Close();

}

2.文本框,标签和按钮练习

点击红色按钮,将文本框中的文字颜色变成红色,同时把该按钮变成不可用(提示:

修改按钮的Enabled属性为false使其不可用);

点击黑色按钮,将文本框中的文字颜色变成黑色,同时把该按钮变成不可用;

点击“文本内容复制到标签”将文本框内容复制到下方标签。

namespaceshiyan5_2

textBox1.ForeColor=System.Drawing.Color.Red;

this.button1.Enabled=false;

textBox1.ForeColor=System.Drawing.Color.Black;

this.button2.Enabled=false;

privatevoidbutton3_Click(objectsender,EventArgse)

label1.Text=textBox1.Text;

3.定时器练习

在窗体中显示字符,每隔1秒字符移动一定距离,先右移,移到右边界,再左移,移到左边界,又一次右移,如此循环。

(提示:

修改标签的Left属性值)

namespaceshiyan5_3

privateboolMoveToRight=true;

privatevoidtimer1_Tick(objectsender,EventArgse)

intx=label1.Location.X;

inty=label1.Location.Y;

intincrement=10;

if(MoveToRight)

if((x+label1.Size.Width)+increment>

=this.ClientRectangle.Width)MoveToRight=false;

else

label1.Location=newPoint(x+increment,y);

if(!

MoveToRight)

if(x-increment<

=0)

MoveToRight=true;

label1.Location=newPoint(x-increment,y);

 

4.复选框、单选框、组合框练习

实现如图所示的功能。

要求对相应控件做了设置之后,马上见到对应的字体效果。

清除按钮用来清除文本框中的文字内容,退出按钮用来退出程序。

namespaceshiyan5_4

textBox1.Text="

;

privatevoidradioButton1_CheckedChanged(objectsender,EventArgse)

textBox1.Font=newSystem.Drawing.Font("

宋?

体¬

15f);

privatevoidradioButton2_CheckedChanged(objectsender,EventArgse)

楷?

15f);

privatevoidradioButton4_CheckedChanged(objectsender,EventArgse)

黑¨

²

privatevoidradioButton3_CheckedChanged(objectsender,EventArgse)

隶¢

£

¤

书º

¦

privatevoidcheckBox1_CheckedChanged(objectsender,EventArgse)

if(checkBox1.Checked)

textBox1.Font=newFont("

15f,FontStyle.Bold);

privatevoidcheckBox2_CheckedChanged(objectsender,EventArgse)

if(checkBox2.Checked)

15f,FontStyle.Italic);

privatevoidcheckBox3_CheckedChanged(objectsender,EventArgse)

if(checkBox3.Checked)

15f,FontStyle.Underline);

privatevoidcheckBox4_CheckedChanged(objectsender,EventArgse)

if(checkBox4.Checked)

15f,FontStyle.Strikeout);

privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)

comboBox1.SelectedItem=newFont("

textBox1.Font.Size);

5.列表框练习

实现程序如下功能:

在文本框中输入水果,点击添加按钮将输入的水果添加到列表框中,如果列表框中已存在此种水果则不添加;

在列表框中选中某些水果后点击删除,删除这些果;

点击清除按钮将列表框中的所有水果都清除。

namespaceshiyan5_5

{publicpartialclassTestList:

{publicTestList()

{InitializeComponent();

privatevoidAddButton_Click(objectsender,EventArgse)

{boolrepeatJudege=false;

if(textBox.Text.Trim()!

="

{foreach(stringiteminFruitListBox.Items)

{if(textBox.Text==item)

{MessageBox.Show("

列表已有"

+textBox.Text,"

错误提醒"

MessageBoxButtons.OK,MessageBoxIcon.Error);

repeatJudege=true;

break;

repeatJudege)

FruitListBox.Items.Add(textBox.Text.Trim());

textBox.Text="

else

MessageBox.Show("

输入不能为空值"

"

MessageBoxButtons.OK,MessageBoxIcon.Error);

privatevoidDelButton_Click(objectsender,EventArgse)

{intcount=FruitListBox.SelectedItems.Count;

if(count!

{for(inti=0;

i<

count;

i++)

{FruitListBox.Items.Remove(FruitListBox.SelectedItems[0]);

请选中删除项"

privatevoidDelAllButton_Click(objectsender,EventArgse)

{if(FruitListBox.Items.Count!

=0)

FruitListBox.Items.Clear();

表中为空"

privatevoidTestList_Load(objectsender,EventArgse)

{}

6.简单记事本。

使用菜单方式实现字体选择和文字颜色的选择;

使用工具栏方式实现字体选择和文字颜色的选择;

使用状态栏显示当前输入的文字的个数信息。

namespaceshiyan5_6

{publicpartialclassForm1:

{publicForm1()

privatevoid字体选择ToolStripMenuItem_Click(objectsender,EventArgse)

{FontDialogfd=newFontDialog();

if(fd.ShowDialog()==DialogResult.OK)

{textBox1.Font=fd.Font;

privatevoidForm1_Load(objectsender,EventArgse)

{toolStripStatusLabel2.Text="

0"

privatevoidtoolStripButton1_Click(objectsender,EventArgse)

privatevoid则提示颜色ToolStripMenuItem_Click(objectsender,EventArgse)

{ColorDialogfd=newColorDialog();

{textBox1.ForeColor=fd.Color;

privatevoidtoolStripButton2_Click(objectsender,EventArgse)

privatevoidtextBox1_TextChanged(objectsender,EventArgse)

{toolStripStatusLabel2.Text=textBox1.Text.Length.ToString();

7.简单图片查看器。

要求使用PictureBox和ImageList控件。

namespaceshiyan5_7

{if(label1.Text=="

1"

{btback.Enabled=false;

pictureBox1.Image=imageList1.Images[0];

inti=0;

privatevoidbtback_Click(objectsender,EventArgse)

{btnext.Enabled=true;

if(label1.Text!

{i--;

label1.Text=(Convert.ToInt16(label1.Text)-1).ToString();

pictureBox1.Image=imageList1.Images[i];

if(i==0)

btback.Enabled=false;

privatevoidbtnext_Click(objectsender,EventArgse)

{btback.Enabled=true;

6"

{i++;

label1.Text=(Convert.ToInt16(label1.Text)+1).ToString();

pictureBox1.Image=imageList1.Images[i];

if(i==5)

btnext.Enabled=false;

实验总结(结论或问题分析):

通过本次实验,进一步熟悉了窗体的概念知识,对于窗体的常用属性有了一定程度的了解,学会了文本操作类控件中的标签控件和文本控件的使用方法,加深了对选择操作类控件中的复选框、单选框、列表框及组合框的使用方法的理解。

实验成绩

任课教师签名

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2