C#实验5掌握窗体的设计和用户界面设计.docx

上传人:b****8 文档编号:10130246 上传时间:2023-02-08 格式:DOCX 页数:19 大小:105.87KB
下载 相关 举报
C#实验5掌握窗体的设计和用户界面设计.docx_第1页
第1页 / 共19页
C#实验5掌握窗体的设计和用户界面设计.docx_第2页
第2页 / 共19页
C#实验5掌握窗体的设计和用户界面设计.docx_第3页
第3页 / 共19页
C#实验5掌握窗体的设计和用户界面设计.docx_第4页
第4页 / 共19页
C#实验5掌握窗体的设计和用户界面设计.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

C#实验5掌握窗体的设计和用户界面设计.docx

《C#实验5掌握窗体的设计和用户界面设计.docx》由会员分享,可在线阅读,更多相关《C#实验5掌握窗体的设计和用户界面设计.docx(19页珍藏版)》请在冰豆网上搜索。

C#实验5掌握窗体的设计和用户界面设计.docx

C#实验5掌握窗体的设计和用户界面设计

实验报告

学院:

计算机科学与信息工程学院专业:

网络工程班级:

网络091

姓名

学号

实验组

实验时间

2010-5-17

指导教师

成绩

实验项目名称

实验五

实验目的

学习和掌握窗体的设计和用户界面设计.

实验内容

1.在Proj8-4项目中添加一个窗体Form5,在学生结构数组存放10名学生的记录,然后根据用户指定的学号显示相应的学生记录。

其运行界面如图8.84所示,这里是从组合框中选择3时,在学生记录分组框中显示该学号的记录.

2.在Proj9-2项目中设计一个窗体Form2,其中包含有TreeView和一个ListView控件和控件,单击控件TreeView1中某个接点时,在ListView1控件中显示所有的子接点,并通过弹出式菜单选择TreeView控件的大图标,图标,列表和完整图标等4种视图显示模式.

例如,在TreeView控件中单击”鱼类”节点,其结果如图9.48所示,单击鼠标右键出现如图9.49所示的弹出式菜单,丛中选择一想,则TreeView控件以该模式显示其中的各项.

实验环境

Pc机

Visualstudio2005

实验步骤

1.编写程序

2.运行程序

3.得出实验结果

实验程序

1.实验程序:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

using11;

namespaceProj8_1

{

publicpartialclassForm8:

Form

{

Student[]Stud={newStudent(1,"李莉","男",091,newDateTime(1990,9,4)),

newStudent(2,"高节","女",2,newDateTime(1992,2,11)),

newStudent(3,"罗文","男",1,newDateTime(1990,7,6)),

newStudent(4,"魏晨","男",3,newDateTime(1992,8,17)),

newStudent(5,"徐文","男",2,newDateTime(1991,5,18)),

newStudent(6,"张洁","男",3,newDateTime(1990,1,9)),

newStudent(7,"王丽","男",2,newDateTime(1993,4,10)),

newStudent(8,"周密","女",2,newDateTime(1992,5,22)),

newStudent(9,"李咯","男",1,newDateTime(1993,5,1))};

publicForm8()

{

InitializeComponent();

}

privatevoidForm8_Load(objectsender,EventArgse)

{

foreach(StudentstudentinStud)

comboBox1.Items.Add(student.num);

}

privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)

{

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

foreach(StudentstudentinStud)

if(Convert.ToInt32(comboBox1.Text)==student.num)

{

textBox1.Text=Convert.ToString(student.num);

textBox2.Text=Convert.ToString(student.name);

textBox3.Text=Convert.ToString(student.sex);

textBox4.Text=Convert.ToString(student.grade);

textBox5.Text=Convert.ToString(student.birthdate);

}

}

}

}

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

namespace11

{

publicstructStudent

{

publicintnum;

publicstringname;

publicstringsex;

publicintgrade;

publicDateTimebirthdate;

publicStudent(intnum1,stringname1,stringsex1,intgrade1,DateTimebirth)

{

name=name1;

num=num1;

sex=sex1;

grade=grade1;

birthdate=birth;

}

};

}

2.实验程序:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceProj9_2

{

publicpartialclassForm1:

Form

{

publicForm1()

{

InitializeComponent();

}

privatevoidtreeView1_AfterSelect(objectsender,TreeViewEventArgse)

{

TreeNodenode=treeView1.SelectedNode;

ListViewItemitemx=newListViewItem();

listView1.GridLines=true;

if(node==treeView1.Nodes[1])

{

listView1.View=View.LargeIcon;

listView1.SmallImageList=imageList1;

listView1.LargeImageList=imageList2;

itemx=listView1.Items.Add("鲨鱼",0);

itemx=listView1.Items.Add("热带鱼",1);

itemx=listView1.Items.Add("金鱼",2);

}

}

privatevoid大图标ToolStripMenuItem_Click(objectsender,EventArgse)

{

listView1.View=View.LargeIcon;

}

privatevoid小图标ToolStripMenuItem_Click(objectsender,EventArgse)

{

listView1.View=View.SmallIcon;

}

privatevoid列表ToolStripMenuItem_Click(objectsender,EventArgse)

{

listView1.View=View.List;

}

privatevoid完整图标ToolStripMenuItem_Click(objectsender,EventArgse)

{

listView1.View=View.Tile;

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

listView1.Clear();

}

}

}

namespaceProj9_2

{

partialclassForm1

{

///

///必需的设计器变量。

///

privateSystem.ComponentModel.IContainercomponents=null;

///

///清理所有正在使用的资源。

///

///如果应释放托管资源,为true;否则为false。

protectedoverridevoidDispose(booldisposing)

{

if(disposing&&(components!

=null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#regionWindows窗体设计器生成的代码

///

///设计器支持所需的方法-不要

///使用代码编辑器修改此方法的内容。

///

privatevoidInitializeComponent()

{

ponents=newSystem.ComponentModel.Container();

System.Windows.Forms.TreeNodetreeNode25=newSystem.Windows.Forms.TreeNode("猪");

System.Windows.Forms.TreeNodetreeNode26=newSystem.Windows.Forms.TreeNode("牛");

System.Windows.Forms.TreeNodetreeNode27=newSystem.Windows.Forms.TreeNode("羊");

System.Windows.Forms.TreeNodetreeNode28=newSystem.Windows.Forms.TreeNode("哺乳动物",newSystem.Windows.Forms.TreeNode[]{

treeNode25,

treeNode26,

treeNode27});

System.Windows.Forms.TreeNodetreeNode29=newSystem.Windows.Forms.TreeNode("鲨鱼");

System.Windows.Forms.TreeNodetreeNode30=newSystem.Windows.Forms.TreeNode("热带鱼");

System.Windows.Forms.TreeNodetreeNode31=newSystem.Windows.Forms.TreeNode("金鱼");

System.Windows.Forms.TreeNodetreeNode32=newSystem.Windows.Forms.TreeNode("鱼类",newSystem.Windows.Forms.TreeNode[]{

treeNode29,

treeNode30,

treeNode31});

System.Windows.Forms.TreeNodetreeNode33=newSystem.Windows.Forms.TreeNode("大鸟");

System.Windows.Forms.TreeNodetreeNode34=newSystem.Windows.Forms.TreeNode("菜鸟");

System.Windows.Forms.TreeNodetreeNode35=newSystem.Windows.Forms.TreeNode("猫头鹰");

System.Windows.Forms.TreeNodetreeNode36=newSystem.Windows.Forms.TreeNode("鸟类",newSystem.Windows.Forms.TreeNode[]{

treeNode33,

treeNode34,

treeNode35});

System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(Form1));

this.splitContainer1=newSystem.Windows.Forms.SplitContainer();

this.treeView1=newSystem.Windows.Forms.TreeView();

this.listView1=newSystem.Windows.Forms.ListView();

this.imageList2=newSystem.Windows.Forms.ImageList(ponents);

this.imageList1=newSystem.Windows.Forms.ImageList(ponents);

this.contextMenuStrip1=newSystem.Windows.Forms.ContextMenuStrip(ponents);

this.大图标ToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();

this.小图标ToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();

this.列表ToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();

this.完整图标ToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();

this.button1=newSystem.Windows.Forms.Button();

this.splitContainer1.Panel1.SuspendLayout();

this.splitContainer1.Panel2.SuspendLayout();

this.splitContainer1.SuspendLayout();

this.contextMenuStrip1.SuspendLayout();

this.SuspendLayout();

//

//splitContainer1

//

this.splitContainer1.Dock=System.Windows.Forms.DockStyle.Fill;

this.splitContainer1.Location=newSystem.Drawing.Point(0,0);

this.splitContainer1.Name="splitContainer1";

//

//splitContainer1.Panel1

//

this.splitContainer1.Panel1.Controls.Add(this.button1);

this.splitContainer1.Panel1.Controls.Add(this.treeView1);

//

//splitContainer1.Panel2

//

this.splitContainer1.Panel2.Controls.Add(this.listView1);

this.splitContainer1.Size=newSystem.Drawing.Size(284,262);

this.splitContainer1.SplitterDistance=113;

this.splitContainer1.TabIndex=0;

//

//treeView1

//

this.treeView1.Location=newSystem.Drawing.Point(3,0);

this.treeView1.Name="treeView1";

treeNode25.Name="节点2";

treeNode25.Text="猪";

treeNode26.Name="节点3";

treeNode26.Text="牛";

treeNode27.Name="节点4";

treeNode27.Text="羊";

treeNode28.Name="节点0";

treeNode28.NodeFont=newSystem.Drawing.Font("宋体",9F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));

treeNode28.Text="哺乳动物";

treeNode29.Name="节点6";

treeNode29.Text="鲨鱼";

treeNode30.Name="节点9";

treeNode30.Text="热带鱼";

treeNode31.Name="节点10";

treeNode31.Text="金鱼";

treeNode32.Name="节点5";

treeNode32.Text="鱼类";

treeNode33.Name="节点12";

treeNode33.Text="大鸟";

treeNode34.Name="节点13";

treeNode34.Text="菜鸟";

treeNode35.Name="节点14";

treeNode35.Text="猫头鹰";

treeNode36.Name="节点11";

treeNode36.Text="鸟类";

this.treeView1.Nodes.AddRange(newSystem.Windows.Forms.TreeNode[]{

treeNode28,

treeNode32,

treeNode36});

this.treeView1.Size=newSystem.Drawing.Size(107,262);

this.treeView1.TabIndex=0;

this.treeView1.AfterSelect+=newSystem.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);

//

//listView1

//

this.listView1.ContextMenuStrip=this.contextMenuStrip1;

this.listView1.LargeImageList=this.imageList2;

this.listView1.Location=newSystem.Drawing.Point(-1,3);

this.listView1.Name="listView1";

this.listView1.Size=newSystem.Drawing.Size(168,259);

this.listView1.SmallImageList=this.imageList1;

this.listView1.TabIndex=0;

this.listView1.UseCompatibleStateImageBehavior=false;

//

//imageList2

//

this.imageList2.ImageStream=((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList2.ImageStream")));

this.imageList2.TransparentColor=System.Drawing.Color.Transparent;

this.imageList2.Images.SetKeyName(0,"Koala.jpg");

this.imageList2.Images.SetKeyName(1,"Penguins.jpg");

this.imageList2.Images.SetKeyName(2,"Jellyfish.jpg");

//

//imageList1

//

this.imageList1.ImageStream=((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));

this.imageList1.TransparentColor=System.Drawing.Color.Transparent;

this.imageList1.Images.SetKeyName(0,"Koala.jpg");

this.imageList1.Images.SetKeyName(1,"Penguins.jpg");

this.imageList1.Images.SetKeyName(2,"Jellyfish.jpg");

//

//contextMenuStrip1

//

this.contextMenuStrip1.Items.AddRange(new

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

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1