有关NotifyIcon的使用

NotifyIcon可以在指定在状态区域创建一个图标,为了使用该控件,可执行以下步骤:
1、在窗体上拖放一个NotifyIcon控件
2、设置NotifyIcon的Icon和Text属性,Icon指定状态栏显示的图标,Text用于显示一个ToolTip
3、在窗体中加入如下代码
 1#Region "Notify Icon code for icon in windows status bar area"
 2    Private Sub MainForm_Deactivate(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Deactivate
 3
 4        ' This will force the NotifyIcon to work
 5        If Me.WindowState = FormWindowState.Minimized Then
 6            Me.Visible = False
 7        End If
 8
 9    End Sub

10
11    Dim preState As Integer
12    Private Sub MainForm_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Resize
13        '记住窗体最小化前的状态,以便在单击窗体时恢复到最小化前的状态
14        If Me.WindowState <> FormWindowState.Minimized Then
15            preState = Me.WindowState
16        End If
17    End Sub

18
19    Private Sub NotifyIcon1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles NotifyIcon1.Click
20
21        ' set the application back to it's normal state from the 
22        ' notify icon on the status bar of Windows
23        Me.Cursor = Cursors.AppStarting
24        If Me.Visible = False Then
25            Me.Visible = True
26        Else
27            Me.Visible = False
28        End If
29
30        If Me.WindowState = FormWindowState.Minimized Then
31            Me.WindowState = preState 'FormWindowState.Normal
32        Else
33            Me.WindowState = FormWindowState.Minimized
34        End If
35        Me.Cursor = Cursors.Default
36    End Sub

37
38#End Region
posted on 2005-05-07 14:35  enjoy .net  阅读(1326)  评论(0编辑  收藏  举报