1、VB课程设计青 岛 农 业 大 学理学与信息科学学院VB.NET实习课程设计报告设 计 题 目 VB.NET课程设计 学生专业班级 通信1002班 学生姓名(学号) 程显聪(20102743) 指 导 教 师 苏万历 老师 完 成 时 间 2011-6-13 实 习(设计)地点 信息楼211 2011 年 6 月 14 日一 设计目的:利用所学vb编程知识编写一个有多重窗体,集合 文件管理系统,图片查看器 ,文本编辑器 三个功能为一体的应用软件。其中文本编辑器不仅有普通编辑器的所有功能 还添加了多个用于计算的窗体,用于在文本编辑过程中数据的计算。二设计内容:1登陆界面:登陆界面需要添加的控件有
2、: 在右侧的工具栏中分别添加控件 lable1, lable2 ,lable3, lable4,textbox1 ,textbox2,picturebox1, button1,button2。完成后 再详细规划每一个控件的功能,其界面如图一所示: 图一完成登录界面的修饰整理后,双击登陆按钮进入代码区 通过编写登录按钮的功能来完成登陆的相关功能。其详细的代码如下: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butt
3、on1.Click Dim psw As String Dim n As Integer If TextBox1.Text = 20102743 Then psw = TextBox2.Text If psw = 123 Then Me.Hide() Form2.Show() End If Else MsgBox(密码或用户账号错误) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close
4、() End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged End Sub Private Sub Label2_Click(ByVal sender As Syst
5、em.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private
6、Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End SubEnd Class登录按钮功能定义代码: Private Sub Button1_Click(ByVal sender As System.O
7、bject, ByVal e As System.EventArgs) Handles Button1.Click Dim psw As String 声明变量 Dim n As Integer规定 如果账户栏输入的是 账号 20102743 再往下判断密码栏的输入内容如果是 123,则执行以下语句 If TextBox1.Text = 20102743 Then psw = TextBox2.Text If psw = 123 Then Me.Hide() Form2.Show() End If其中代码 ;Me.Hide() Form2.Show() 的功能 是实现窗口之间的切换操作,相关登
8、录信息核实之后,将进入 form2, 代码Else MsgBox(密码或用户账号错误) End If End Sub是 如果账户和密码错误 则弹出对话框提示。在这个地方是利用了IF语句进行判断Form2的设计如下:首先添加控件: lable1,lable2,lable3,lable4,button1 ,button2,button3,button4,piturebox12Form2:添加完控件后再做相应的修饰操作,完成界面如下图二所示: 图二 Form 2的功能是将整个的功能做一个分区,有三个模块 文件管理器 图片查看器 文本编辑器,通过此界面可以选择进入相应模块完成相应操作。该模块的名字为功
9、能分区。单击退出按钮,键返回到登陆界面 如果想彻底关闭程序单击登陆界面的关闭按钮即可关闭程序。该功能的实现代码如下:Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Hide() Form1.Show() End Sub单击文件管理器左侧的单击进入按钮,即可进入文件管理器程序。其功能的实现代码如下:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
10、 As System.EventArgs) Handles Button1.Click Me.Hide() Form3.Show() End Sub单击图片查看器左侧的单击进入按钮,即可进入图片查看器程序。其功能的实现代码如下:Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Hide() Form4.Show() End Sub单击文本编辑器左侧的单击进入按钮,即可进文本编辑器程序。其功能的实现代码如下:Private S
11、ub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Hide() Form5.Show() End Sub整个Form2的代码如下所示:Public Class Form2 Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) End Sub Private
12、 Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Hide() Form3.Show() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Hide() Form4.Show() End Sub Private Sub Button2_Click(ByV
13、al sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Hide() Form5.Show() End Sub Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Labe
14、l4.Click End Sub Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub Private Sub Label1_Click(ByVal sender As System.Object,
15、 ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Hide()
16、 Form1.Show() End SubEnd Class单击文件管理器左侧的按钮进入文件管理器程序的操作界面需要从工具栏中添加的控件如下,lable1,button1,button2,button3,button4,button5,textbox1,picturebox1.完成此界面的修饰工作后其效果图如下图三所示: 图三该界面所有的代码如下所示: Imports System.IOPublic Class Form3 Private Const DEFAULTFILE As String = NewFile Private currentFile As String = Private
17、Sub DriveListbox1_selectedindexchanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ DriveListBox1.SelectedIndexChanged DirListBox1.Path = DriveListBox1.Drive End Sub Private Sub DirListBox1_change(ByVal sender As System.Object, ByVal e As System.EventArgs) FileListBox1.Pat
18、h = DirListBox1.Path TextBox1.Text = FileListBox1.Path End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub以上代码是实现 Dirlistbox和drivelistbox控件同步,filelistbox控件和dirlist控件同步。Drivelistbox控件用于驱动器的操作,dirlistbox控件用于文件夹的操作,filelistbox 用于文件的操作。单击新建按钮是现在当前显示路
19、径下新建一个文件,其相应的功能代码实现如下: Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fpath As String Dim fname As String Dim s As Stream fpath = DirListBox1.Path If fpath = Then MsgBox(请选择文件夹, 提示) End If fname = InputBox(请输入新的文件名和扩展名 & Chr(10) & Ch
20、r(13) & 输入) If fname Then s = File.Create(fpath & fname) s.Close() End If End Sub 单击移动按钮 将所选定的文件移动到相应制定的文件当中去。其相应的代码实现如下: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim fpath As String Dim fnewpath As String Dim fname As String fpath =
21、 DirListBox1.Path 将选定的文件的路径付给fpath fname = FileListBox1.FileName 选定的文件的名字付给fname当中。 fnewpath = InputBox(请输入目标文件夹路径 & Chr(10) & Chr(13) & 如 D:MYDATA, 输入)弹出对话框 提示输入目标文件夹路径 并将其赋值给fnewpath中进行存储。 File.Move(fpath & fname, fnewpath & fname)End Sub单击复制按钮就会实现尖所选的文件进行复制的操作,其相应功能的代码实现如下;Private Sub Button3_Cli
22、ck(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click先进性变量的定义: Dim fpath As String Dim fnewpath As String Dim fname As String fpath = DirListBox1.Path fname = FileListBox1.FileName会弹出对话框 提示输入需要将所选文件复制到的文档下的相关路径:在所弹出的对话框中输入相应信息并将其赋值给fnewpath中 fnewpath = InputBox(请输入文件夹路
23、径 & Chr(10) & Chr(13) & 如 D:MYDATA, 输入) File.Copy(fpath & fname, fnewpath & fname)用filecopy函数实现相关的操作 End Sub单击删除按钮即可将当前所选定的文件在当前路径下进行删除的操作,其相应的功能代码实现如下: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 首先定义相关变量 Dim fpath As String Dim fname
24、As String Dim mes As Integer fpath = DirListBox1.Path fname = FileListBox1.FileName 用IF语句进行判断 If fname = Then MsgBox(请选择源文件, 提示) Else mes = MsgBox(确实要删除 & fpath & fname & 吗?, MsgBoxStyle.OkCancel, 确认) If mes = vbOK Then 单击了所弹出的对话框中的确定按钮之后,程序执删除操作。其代码如下: File.Delete(fpath & fname)用file.delete函数进行删除操作
25、。 End If End If End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End Sub Private Sub Label1_C
26、lick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub FileListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox1.SelectedIndexChanged End Sub Private Sub DirListBox1_SelectedIndexChanged(ByVal
27、 sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged End Sub单机返回按钮程序就会返回上一级操作界面功能分区。其相应的代码如下: Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.Hide() Form2.Show() End SubEnd Class返回到功能分区操作界面以后,选择
28、图片查看器,单击其左边的按钮,即可进入图片查看操作界面。需要的控件有:picturebox1,button1,button2,button3完成相应的修饰操作之后,其 图四如图四所示。在PICTUREbox1中的属性栏中选择图片总的省略号按钮,在弹出的对话框中选择向系统中添加图片,在选择相应的图片进行查看。给界面的总代码如下:Public Class Form4单击翻页按钮即可实现查看操作 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.C
29、lick 声明动态变量I, Static i As Integer = 1 i的初始值是1 利用case 操作进行图片的翻转操作 Select Case i Case 1 PictureBox1.Image = My.Resources.dream_world Case 2 PictureBox1.Image = My.Resources.dream_world_5 Case 3 PictureBox1.Image = My.Resources.shot0016 Case 4 PictureBox1.Image = My.Resources.unhwhertitled Case 5 Pictu
30、reBox1.Image = My.Resources.unhwhwwtitled Case 6 PictureBox1.Image = My.Resources.untehhitled Case 7 PictureBox1.Image = My.Resources.untehhitled1 Case 8 PictureBox1.Image = My.Resources.unti144tled Case 9 PictureBox1.Image = My.Resources.untihwhdtled Case 10 PictureBox1.Image = My.Resources.untitdf
31、bdfbdbdsled Case 11 PictureBox1.Image = My.Resources.untitl12ed Case 12 PictureBox1.Image = My.Resources.untiwhyergdtled End Select If i = 12 Then,但是二张图片全部看完时。就是i的值为1. i = 1 Else i = i + 1 End IfEnd Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End S
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1