1 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
Public Class MainForm
Private CanClose As Boolean
Public ContextMenu1 As New ContextMenu
Public NotifyIcon1 As New NotifyIcon
Private mnuShowHideApp, MnuSuspendApp, mnuExitApp, mnuShowHideHelp As MenuItem
Private frmHelp As FormHelp = New FormHelp
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.ShowInTaskbar = False
Me.TopMost = True
Me.Visible = False
frmHelp.ShowInTaskbar = False
frmHelp.TopMost = True
frmHelp.Visible = False
CreateIconMenuStructure()
AddHandler mnuShowHideApp.Click, AddressOf AppShowHide
AddHandler mnuExitApp.Click, AddressOf ExitApp
AddHandler mnuShowHideHelp.Click, AddressOf ShowHideHelp
End Sub
Public Sub CreateIconMenuStructure()
' Add menu items to shortcut menu.
mnuShowHideApp = ContextMenu1.MenuItems.Add("&AppShowHide Application")
MnuSuspendApp = ContextMenu1.MenuItems.Add("S&uspend Application")
mnuExitApp = ContextMenu1.MenuItems.Add("E&xit")
mnuShowHideHelp = ContextMenu1.MenuItems.Add("&ShowHideHelp")
' Set properties of NotifyIcon component.
NotifyIcon1.Icon = My.Resources.Annotate_Default
'NotifyIcon1.Icon = New System.Drawing.Icon _
' (System.Environment.GetFolderPath _
' (System.Environment.SpecialFolder.Personal) _
' & "\Icon.ico")
NotifyIcon1.Text = "Right-click me!"
NotifyIcon1.Visible = True
NotifyIcon1.ContextMenu = ContextMenu1
End Sub
Private Sub ExitApp(ByVal sender As Object, ByVal e As EventArgs)
CanClose = True
Me.Close()
End Sub
Private Sub ShowHideHelp(ByVal sender As Object, ByVal e As EventArgs)
frmHelp.Visible = Not frmHelp.Visible
End Sub
Private Sub AppShowHide(ByVal sender As Object, ByVal e As EventArgs)
Me.Visible = Not Me.Visible
End Sub
Private Sub MainForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not CanClose Then
e.Cancel = True
End If
End Sub
End Class
Public Class FormHelp
Private Sub FormHelp_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
e.Cancel = True
End Sub
End Class |
Partager