实验三c#实验报告.docx
《实验三c#实验报告.docx》由会员分享,可在线阅读,更多相关《实验三c#实验报告.docx(13页珍藏版)》请在冰豆网上搜索。
实验三c#实验报告
“C#”课程实验报告
实验名称
实验三控件应用2
实验序号
二
姓名
实验日期
一、实验目的和要求
1.掌握ListView、TreeView控件的使用。
2.掌握菜单、工具栏、状态栏控件的使用。
3.掌握文件、颜色、字体等通用对话框的使用。
4.掌握多窗体应用程序的创建。
二、实验项目摘要
1.设计一个选课界面程序,将课程详细信息显示在表格中,请使用ListView控件设计表格。
其中课程信息包括课程编号,课程名称、课程学时和授课教师等。
用户可选择多门课程,单击“选课”按钮,将所选的课程信息显示在另一个窗体上。
2.使用TreeView控件,建立一个超市商品分类列表,可以添加、删除各类商品信息。
3.设计一个字符串处理应用程序。
要求利用菜单和工具栏完成各种字符串处理任务,如字符串比较、查找、求字串、拆分、合并等。
利用状态栏显示当前的操作。
4.制作一个文档编辑器程序,可以进行文档的打开和保存、基本的编辑操作以及颜色和字体的设置等。
5.电子相册制作。
在时钟的控制下,图片将按照先后次序依次显示在画面上,并配上音乐,每幅画配上相应的文字。
三、实验结果与分析
第二题:
设计思路:
使用TreeView控件,建立一个超市商品分类列表,可以添加、删除各类商品信息。
步骤:
1、按照提示输入类别上商品名称;分别添加对应的商品种类和商品名称。
2.删除功能:
选中商品,点击删除,可删除选中的商品,选中类别,点击删除,可删除该目录下的全部商品。
3.点击清空可删除所有的目录及商品。
第5题:
设计思路:
在时钟的控制下,图片将按照先后次序依次显示在画面上,并配上音乐,每幅画配上相应的文字。
1、选择预览图片
2.添加预览图片
3、图片自动播放预览
附录
源代码:
第二题:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace实验3._2
{publicpartialclassForm1:
Form
{publicForm1()
{InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{TreeNodenewnode=newTreeNode(this.textBox1.Text,0,1);
this.treeView1.Nodes.Add(newnode);
this.treeView1.Select();
}
privatevoidbutton2_Click(objectsender,EventArgse)
{TreeNodeselectednode=this.treeView1.SelectedNode;
if(selectednode==null)
{MessageBox.Show("请选中节点");
return;
}
if(selectednode.Parent!
=null)
{MessageBox.Show("不能添加");
return;
}
TreeNodenewnode=newTreeNode(this.textBox2.Text,2,3);
selectednode.Nodes.Add(newnode);
selectednode.Expand();
this.treeView1.Select();
}
privatevoidbutton4_Click(objectsender,EventArgse)
{treeView1.Nodes.Clear();
}
privatevoidbutton3_Click(objectsender,EventArgse)
{TreeNodeselectnode=this.treeView1.SelectedNode;
if(selectnode==null)
{MessageBox.Show("请选中节点");
return;
}
TreeNodeparentnode=selectnode.Parent;
if(parentnode==null)
this.treeView1.Nodes.Remove(selectnode);
else
parentnode.Nodes.Remove(selectnode);
this.treeView1.Select();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
}
}
}
第5题:
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
namespace图片自动浏览器
{
///
///Form1的摘要说明。
///
publicclassForm1:
System.Windows.Forms.Form
{
privateSystem.ComponentModel.IContainercomponents;
privateSystem.Windows.Forms.PictureBoxpictureBox1;
privateSystem.Windows.Forms.Buttonbutton1;
privateSystem.Windows.Forms.ListBoxlistBox1;
privateSystem.Windows.Forms.Buttonbutton2;
privateSystem.Windows.Forms.OpenFileDialogopenFileDialog1;
privateSystem.Windows.Forms.Timertimer1;
privateLabellabel1;
privateintPicNo;//定义数据成员变量PicNo,表示显示图片号
publicForm1()
{
//
//Windows窗体设计器支持所必需的
//
InitializeComponent();
//
//TODO:
在InitializeComponent调用后添加任何构造函数代码
//
}
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!
=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#regionWindows窗体设计器生成的代码
privatevoidInitializeComponent()
{
ponents=newSystem.ComponentModel.Container();
this.pictureBox1=newSystem.Windows.Forms.PictureBox();
this.button1=newSystem.Windows.Forms.Button();
this.listBox1=newSystem.Windows.Forms.ListBox();
this.button2=newSystem.Windows.Forms.Button();
this.openFileDialog1=newSystem.Windows.Forms.OpenFileDialog();
this.timer1=newSystem.Windows.Forms.Timer(ponents);
this.label1=newSystem.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
//pictureBox1
//
this.pictureBox1.Location=newSystem.Drawing.Point(12,52);
this.pictureBox1.Name="pictureBox1";
this.pictureBox1.Size=newSystem.Drawing.Size(184,216);
this.pictureBox1.SizeMode=System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex=0;
this.pictureBox1.TabStop=false;
//
//button1
//
this.button1.Location=newSystem.Drawing.Point(212,52);
this.button1.Name="button1";
this.button1.Size=newSystem.Drawing.Size(80,32);
this.button1.TabIndex=1;
this.button1.Text="选择图片";
this.button1.Click+=newSystem.EventHandler(this.button1_Click);
//
//listBox1
//
this.listBox1.ItemHeight=12;
this.listBox1.Location=newSystem.Drawing.Point(212,100);
this.listBox1.Name="listBox1";
this.listBox1.Size=newSystem.Drawing.Size(168,160);
this.listBox1.TabIndex=2;
//
//button2
//
this.button2.Location=newSystem.Drawing.Point(308,52);
this.button2.Name="button2";
this.button2.Size=newSystem.Drawing.Size(72,32);
this.button2.TabIndex=3;
this.button2.Text="浏览";
this.button2.Click+=newSystem.EventHandler(this.button2_Click);
//
//timer1
//
this.timer1.Interval=1000;
this.timer1.Tick+=newSystem.EventHandler(this.timer1_Tick);
//
//label1
//
this.label1.AutoSize=true;
this.label1.Location=newSystem.Drawing.Point(23,18);
this.label1.Name="label1";
this.label1.Size=newSystem.Drawing.Size(269,12);
this.label1.TabIndex=4;
this.label1.Text="通过“选择图片”按钮将所需图片添加到列表框中";
//
//Form1
//
this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);
this.ClientSize=newSystem.Drawing.Size(403,280);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Name="Form1";
this.Text="Form1";
this.Load+=newSystem.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
[STAThread]
staticvoidMain()
{
Application.Run(newForm1());
}
privatevoidForm1_Load(objectsender,System.EventArgse)
{
PicNo=0;
timer1.Enabled=false;//设置定时器不可用
}
privatevoidbutton1_Click(objectsender,System.EventArgse)
//通过“选择图片”按钮将所需图片添加到列表框中
{
//设置过滤器,只显示图像文件
openFileDialog1.Filter="位图文件|*.bmp|GIF文件|*.gif|JPEG文件|*.jpg";
//指定缺省过滤器(默认打开JPEG文件)
openFileDialog1.FilterIndex=3;
openFileDialog1.ShowDialog();//显示“打开”对话框
//将用户选定文件载入列表框
listBox1.Items.Add(openFileDialog1.FileName);
}
privatevoidbutton2_Click(objectsender,System.EventArgse)
{
timer1.Enabled=true;//设置定时器可用
}
privatevoidtimer1_Tick(objectsender,System.EventArgse)
{
listBox1.SelectedIndex=PicNo;
strings=listBox1.SelectedItem.ToString();//得到某一要显示图片的路径
pictureBox1.Image=Image.FromFile(s);//加载图片
PicNo=PicNo+1;//为得到下一张图片做准备
if(PicNo>=listBox1.Items.Count)
//如果是最后一张,则转为第一张
PicNo=0;
}
}
}