软件开发环境与工具实验报告
———————————————————————————————— 作者:
———————————————————————————————— 日期:
软件开发环境与工具实验报告
实验一
托盘程序设计
实验题目:托盘程序设计
实验类型:验证性
专业班级:计算机科学与技术系网络工程方向1003
姓
名:
学
号:2010100331
2012年 10
实验地点:软件实验室二
一.实验目的:
通过本次实验,使学生了解托盘程序的应用及设计思想,利用Timer控件和NotifyIcon控件实现一个动态托盘程序。
二.实验要求:
1、实现动态托盘。
2、关闭窗体时进行隐藏操作。
3、窗体和托盘的转换通过双击实现。
4、托盘所对应主程序的应用自定。
三.源代码:
Public Class 随机数
Dim isclose As Boolean = False
Dim FistIco As Boolean = False
Dim ico1 As System.Drawing.Icon
Dim ico2 As System.Drawing.Icon
Private Sub 开始_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 开始Click
Dim a(9), i, j, n, p As Integer
Dim m As String
Randomize()
a(0) = Int(100 * Rnd()) + 1
For i = 1 To 9
p = 1
While p
Randomize()
a(i) = Int(100 * Rnd()) + 1
For j = 0 To i - 1
If a(j) = a(i) Then
Exit For
End If
If j = i - 1 And a(i) <> a(i - 1) Then
p = 0
End If
Next j
End While
Next i
m = "您抽取的10个整数为: " & Chr(13) & Chr(10)
For i = 1 To 10
If a(i - 1) < 10 Then
m = m & a(i - 1) & " " & " "
Else : m = m & a(i - 1) & " "
End If
If i Mod 5 = 0 Then
m = m & Chr(13) & Chr(10)
End If
Next i
Label2.Text = m
End Sub
Private Sub 退出_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出.Click
End
End Sub ’程序主界面的开始与退出
Private Sub 图标_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 图标.MouseDoubleClick
If Me.WindowState = FormWindowState.Normal Then
Me.WindowState = FormWindowState.Minimized
Else
Me.WindowState = FormWindowState.Normal
End If
End Sub ’双击图标隐藏或显示窗口
Private Sub 随机数 FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.FormOwnerClosing Then
isclose = False
End If
If isclose = False Then
e.Cancel = True
Me.WindowState = FormWindowState.Minimized
Me.Hide()
End If
End Sub ’主窗体的关闭
Private Sub 随机数_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ico1 = New System.Drawing.Icon(Application.StartupPath & "\image\1.ico")
ico2 = New System.Drawing.Icon(Application.StartupPath & "\image\2.ico")
End Sub ’给托盘附加图片
Private Sub 时间块Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 时间块Tick
If FistIco Then
Me.图标Icon = ico1
FistIco = False
Else
Me.图标Icon = ico2
FistIco = True
End If
End Sub ’控制图标闪烁
Private Sub 退出ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出ToolStripMenuItem.Click
End
End Sub
Private Sub 隐藏ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 隐藏ToolStripMenuItem.Click
Me.Hide()
End Sub
Private Sub 显示ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 显示ToolStripMenuItem.Click
Me.Show()
End Sub
Private Sub 托盘_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles 托盘Opening
End Sub ’控制托盘完成隐藏、显示、退出命令
End Class
四.实验相关截图:
五.实验总结:
通过本次通过对NotifyIcon1、Timer、ContextMenuStrip1工具的应用,实现了求10个随机数的动态托盘程序。在设计过程中出现了闪烁图标不能出现的情况,这是设计中的难点。NotifyIcon1、Timer两个工具的结合使用,实现了闪烁的托盘,ContextMenuStrip1工具则实现右击托盘时出现的“隐藏、显示、退出”命令。但是对界面的优化设计没有做出来还需通过学习掌握。
相关热词搜索: 实验 环境 工具 报告 开发