Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to Attach Context Menu with System Tray Icon in Your VB.Net Application

Author: DevASP
Download Source Code : 375_System_tray_menu.zip

In this simple article you will learn that how can you attach context menu with system tray icon and also do tasks on click of this icon.

Create a New Project in VB.Net. Drag a NotifyIcon, Timer and Context menu from tool box and place on form. Now create options on the context menu like simple menu. Now start writing code on different events . Declare Global variables:

 

Dim icon1 As New Icon("ac0036-48.ico")

Dim icon2 As New Icon("ac0036-32.ico")

Dim check As Integer = 0

Dim NAMECHECK As Integer = 0

Write code on from load event

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Timer1.Interval = 300

        Me.Icon = icon1

        NotifyIcon1.Icon = Me.Icon

        Me.NotifyIcon1.Visible = True

        Me.NotifyIcon1.ContextMenu = Me.ContextMenu1

 

End Sub

Write code on timer tick event:

 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

 

        If check = 1 Then

            Me.Icon = icon2

            NotifyIcon1.Icon = Me.Icon

            check = 0

 

        Else

            Me.Icon = icon1

            NotifyIcon1.Icon = Me.Icon

            check = 1

        End If

        If NAMECHECK = 0 Then

            Me.Text = "D"

        ElseIf NAMECHECK = 1 Then

            Me.Text = "DE"

        ElseIf NAMECHECK = 2 Then

            Me.Text = "DEV"

        ElseIf NAMECHECK = 3 Then

            Me.Text = "DEVA"

        ElseIf NAMECHECK = 4 Then

            Me.Text = "DEVAS"

        ElseIf NAMECHECK = 5 Then

            Me.Text = "DEVASP"

        End If

        NAMECHECK += 1

        If NAMECHECK = 6 Then

            NAMECHECK = 0

        End If

 

 

End Sub 

Now write code on context menu items

 

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

 

        NotifyIcon1.Visible = True

        Timer1.Start()

 

End Sub

 

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

 

        Timer1.Stop()

 

End Sub

 

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click

 

        Me.Close()

 

End Sub

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with Redim Statement in VB.Net and its Advantages

Disclaimer - Privacy
© 2002-2017 DevASP.net