Author: DevASP
Tutorial: Crow407
In this simple tutorial 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:
Code
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 = 0Write code on from load event:
Code
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 SubWrite code on timer tick event:
Code
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 SubNow write code on context menu items:
Code
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 SubIf You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
[img]http://i685.photobucket.com/albums/vv215/blackpearl4/THANKS.gif[/img]
PHP & .NET Contributor.


