in

MySoftwareStartup

Dedicated to help those that own or are thinking of owning a software development company

Randy Walker Blog

Randy Walker's Blog website where he shares his experiences while being a software entrepreneur, Microsoft MVP, and industry influencer

VB.Net Code Example for a 'Sub Main' Startup for a System Tray Application with an Infragistics Context Menu

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

        CreateContextMenu()
        Windows.Forms.Application.Run()
    End Sub

    Private Sub CreateContextMenu()
        Dim CurrentTool As ButtonTool

        ToolbarManager = New UltraToolbarsManager
        ContextMenu = New PopupMenuTool("ContextMenu")
        ToolbarManager.Tools.Add(ContextMenu)

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

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

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

        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"
                Windows.Forms.Application.Exit()
            Case "About"
            Case "Help"
        End Select
    End Sub
End Module

Comments

 

J. Ambrose Little said:

Just wanted to post a quick pointer to some great links on the net related to Infragistics. WPF Podcatcher

January 7, 2008 3:05 PM
 

vb sub main form said:

Pingback from  vb sub main form

May 15, 2008 5:13 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About Randy Walker

Randy Walker is the owner and founder Harvest I.T. Inc., which is a Micro ISV that services the Wal-Mart vendor community and Retail Link. He has presented several sessions at various developer conferences on the subject of owning your own software company.
Copyright 2008 Randy Walker
Powered by Community Server (Commercial Edition), by Telligent Systems