NotifyIcon class: display an icon for an application in the notification area : NotifyIcon « GUI « VB.Net Tutorial






Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public NotInheritable Class Form1
    Inherits System.Windows.Forms.Form

    Private contextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents notifyIcon1 As System.Windows.Forms.NotifyIcon
    Private components As System.ComponentModel.IContainer

    <System.STAThread()> _
    Public Shared Sub Main()
        System.Windows.Forms.Application.Run(New Form1)
    End Sub 'Main

    Public Sub New()
        Me.components = New System.ComponentModel.Container
        Me.contextMenu1 = New System.Windows.Forms.ContextMenu
        Me.menuItem1 = New System.Windows.Forms.MenuItem

        Me.contextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem(){Me.menuItem1})

        Me.menuItem1.Index = 0
        Me.menuItem1.Text = "E&xit"

        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Text = "Notify Icon Example"

        Me.notifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)

        notifyIcon1.Icon = New Icon("appicon.ico")

        notifyIcon1.ContextMenu = Me.contextMenu1

        notifyIcon1.Text = "Form1 (NotifyIcon example)"
        notifyIcon1.Visible = True
    End Sub 'New

    Private Sub notifyIcon1_DoubleClick(Sender as object, e as EventArgs) handles notifyIcon1.DoubleClick
        if (me.WindowState = FormWindowState.Minimized) then _
            me.WindowState = FormWindowState.Normal
        me.Activate()
    end sub

    Private Sub menuItem1_Click(Sender as object, e as EventArgs) handles menuItem1.Click
        me.Close()
    end sub

End Class








14.48.NotifyIcon
14.48.1.NotifyIcon class: display an icon for an application in the notification area