有关NotifyIcon的使用
NotifyIcon可以在指定在状态区域创建一个图标,为了使用该控件,可执行以下步骤:
1、在窗体上拖放一个NotifyIcon控件
2、设置NotifyIcon的Icon和Text属性,Icon指定状态栏显示的图标,Text用于显示一个ToolTip
3、在窗体中加入如下代码
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 Object, ByVal 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 Object, ByVal 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 Object, ByVal 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
浙公网安备 33010602011771号