控件使用实验报告Word格式.docx
《控件使用实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《控件使用实验报告Word格式.docx(16页珍藏版)》请在冰豆网上搜索。
![控件使用实验报告Word格式.docx](https://file1.bdocx.com/fileroot1/2022-10/12/bf67d043-1a0a-437b-bf3d-4a94555bc24c/bf67d043-1a0a-437b-bf3d-4a94555bc24c1.gif)
1.认真阅读、掌握和本实验相关的教材内容。
2.设计并编写代码完成题目要求的任务。
3.撰写实验报告。
实验内容与步骤:
1.多窗体练习
实现如图所示功能。
输入用户名后点击登录按钮,弹出右图消息框。
要求在消息框中显示用户输入的用户名和“欢迎你”语句。
点击取消按钮结束程序运行。
源代码:
在窗体forml里面添加如下代码:
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)
MessageBoxShow(this.textBox1.Text+"
欢?
迎?
-你?
!
e?
"
提示o?
消?
息e"
MessageBoxButtons.OK,MessageBoxIcon.lnformation);
privatevoidbutton2_Click(objectsender,EventArgse)
this.Close();
2.文本框,标签和按钮练习
点击红色按钮,将文本框中的文字颜色变成红色,同时把该按钮变成不可用(提示:
修改按钮的Enabled属性为false使其不可用);
点击黑色按钮,将文本框中的文字颜色变成黑色,同时把该按钮变成不可用;
点击“文本内容复
制到标签”将文本框内容复制到下方标签。
usingSystem;
namespaceshiyan5_2
EventArgse)
privatevoidbutton1_Click(objectsender,
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=labell.Location.Y;
intincrement=10;
if
(MoveToRight)
if((x+labell.Size.Width)+increment>
=this.ClientRectangle.Width)MoveToRight
=false;
else
labell.Location=newPoint(x+increment,y);
if(!
MoveToRight)
if(x-increment<
=0)
MoveToRight=true;
labell.Location=newPoint(x-increment,y);
4•复选框、单选框、组合框练习
实现如图所示的功能。
要求对相应控件做了设置之后,马上见到对应的字体效果。
清除按钮用来清除文本框中的文字内容,退出按钮用来退出程序。
町复选匡丝选框.矩合桂【F冋IYW
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Windows.Forms;
namespaceshiyan5_4
publicpartialclassForml:
privatevoidbutton2_Click(objectsender,EventArgse)
this.Close();
privatevoidbutton1_Click(objectsender,EventArgse)
textBox1.Text="
;
privatevoidradioButton1_CheckedChanged(objectsender,EventArgse)
textBox1.Font=newSystem.Drawing.Font(”宋?
体?
?
15f);
privatevoidradioButton2_CheckedChanged(objectsender,EventArgse)
textBox1.Font=newSystem.Drawing.Font(”楷?
15f);
privatevoidradioButton4_CheckedChanged(objectsender,EventArgse)
textBox1.Font=newSystem.Drawing.Font(”黑T体?
privatevoidradioButton3_CheckedChanged(objectsender,EventArgse)
textBox1.Font=newSystem.Drawing.Font(”隶0£
书o"
|"
15f);
privatevoidcheckBox1_CheckedChanged(objectsender,EventArgse)
if(checkBox1.Checked)
textBox1.Font=newFont("
宋?
,15f,FontStyle.Bold);
privatevoidcheckBox2_CheckedChanged(objectsender,EventArgse)
if(checkBox2.Checked)
textBox1.Font=newFont("
体?
?
15f,FontStyle.ltalic);
privatevoidcheckBox3_CheckedChanged(objectsender,EventArgse)
if(checkBox3.Checked)
textBoxl.Font=newFont("
15f,FontStyle.Underline);
privatevoidcheckBox4_CheckedChanged(objectsender,EventArgse)
if(checkBox4.Checked)
15f,FontStyle.Strikeout);
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)
comboBox1.Selectedltem=newFont("
textBox1.Font.Size);
5•列表框练习
实现程序如下功能:
在文本框中输入水果,点击添加按钮将输入的水果添加到列表框中,如果列表框中已存在此种水果则不添加;
在列表框中选中某些水果后点击删除,删除这些果;
点击清除按钮将列表框中的所有水果都清除。
口t列表眶[匸丨回
请输入你盲爱的水果:
香蕉
namespaceshiyan5_5
{publicpartial