Geeks With Blogs
Randy Walker Entrepreneur, VB MVP

It's easy to create an application that uses the NotifyIcon control, you simply add the control to your windows form.  There are even code examples out there that show how to add a Notify Icon through code.  However I had a really hard time finding one that started up from 'Sub Main'.  Add in the fact that I use Infragistics controls and I couldn't find any examples of hooking up a PopupMenu Tool as the context menu ... this took me several hours to hook it all together.

Enjoy ...

Imports Infragistics.Win.UltraWinToolbars

Public Module Startup
    Private WithEvents SystemTrayIcon As New System.Windows.Forms.NotifyIcon
    Private WithEvents ToolbarManager As UltraToolbarsManager
    Private ContextMenu As PopupMenuTool

    Public Sub Main()
        SystemTrayIcon.Icon = New System.Drawing.Icon(".\Images\Keys.ico")
        SystemTrayIcon.Visible = True

    End Sub

    Private Sub CreateContextMenu()
        Dim CurrentTool As ButtonTool

        ToolbarManager = New UltraToolbarsManager
        ContextMenu = New PopupMenuTool("ContextMenu")

        CurrentTool = New ButtonTool("Help")
        CurrentTool.SharedProps.Caption = "&Help"
        CurrentTool.SharedProps.AppearancesSmall.Appearance.Image = System.Drawing.Image.FromFile(".\Images\help.png")

        CurrentTool = New ButtonTool("About")
        CurrentTool.SharedProps.Caption = "&About"

        CurrentTool = New ButtonTool("Exit")
        CurrentTool.SharedProps.Caption = "E&xit"

        CurrentTool = ContextMenu.Tools.AddTool("Help")
        CurrentTool.InstanceProps.IsFirstInGroup = True
        CurrentTool = ContextMenu.Tools.AddTool("About")
        CurrentTool = ContextMenu.Tools.AddTool("Exit")
        CurrentTool.InstanceProps.IsFirstInGroup = True

        ToolbarManager.SetContextMenuUltra(SystemTrayIcon, "ContextMenu")
    End Sub

    Private Sub ToolbarManager_ToolClick(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles ToolbarManager.ToolClick
        Select Case e.Tool.Key
            Case "Exit"
            Case "About"
            Case "Help"
        End Select
    End Sub
End Module

Posted on Friday, December 28, 2007 5:21 AM | Back to top

Comments on this post: VB.Net Code Example for a 'Sub Main' Startup for a System Tray Application with an Infragistics Context Menu

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Randy Walker | Powered by: