Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.NET]How to Attach Context Menu with System Tray Icon


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 = 0


Write 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 Sub


Write 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 Sub


Now 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 Sub


If 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.
Thankssss this is going to be very useful!!! I was searching for this for long time...
Knew this already. But good tutorial, good job!
(May 7, 2010 02:22 PM)Scrat Wrote:  Thankssss this is going to be very useful!!! I was searching for this for long time...

glad i could help....
(May 7, 2010 02:26 PM)TehShrink Wrote:  Knew this already. But good tutorial, good job!

thank you
PHP & .NET Contributor.
I will need this sometime :D

I was just fucking around on a blank project trying to get this to work, but couldn't do it :P
well you have to rewrite some parts of it to meet your needs...
PHP & .NET Contributor.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by iRazorOct 15, 2021 12:35 PM 3 156 Oct 15, 2021 12:35 PM
Last Post: steel iron
[Shell] by Emre_May 30, 2020 05:19 AM 5 235 May 30, 2020 05:19 AM
Last Post: Emre_
[Shell] by Emre_May 28, 2020 09:36 PM 0 114 May 28, 2020 09:36 PM
Last Post: Emre_