473,508 Members | 4,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically add eventhandler for notifyIcon

I am using VB Net 2005 and want to use the notifyicon. I do not have a
form, only a class. I have no problems showing or modifying the
NotifyIcon, however, I am having a problem handling the click event. I
have tried unsuccessfully using AddHandler:

AddHandler nIcon.Click AddressOf nIcon_Click

Private Sub nIcon_Click(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("Click")
End Sub

Any help would be greatly appreciated.

Jan 4 '07 #1
4 2096
where is your add handler at? in the load? does it depend on another event
happening first? compare it to the sample code from MSDN

' Initalize the NofifyIcon object's shortcut menu.
Private Sub InitializeContextMenu()
Dim menuList() As MenuItem = New MenuItem() _
{New MenuItem("Sign In"), New MenuItem("Get Help"), _
New MenuItem("Open")}
Dim clickMenu As New ContextMenu(menuList)
NotifyIcon1.ContextMenu = clickMenu
End Sub
' When user clicks the left mouse button display the shortcut menu.
' Use the SystemInformation.PrimaryMonitorMaximizedWindowSiz e property
' to place the menu at the lower corner of the screen.
Private Sub NotifyIcon1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles NotifyIcon1.Click

Dim windowSize As System.Drawing.Size = _
SystemInformation.PrimaryMonitorMaximizedWindowSiz e
Dim menuPoint As System.Drawing.Point = New System.Drawing.Point _
(windowSize.Width - 180, windowSize.Height - 5)
menuPoint = Me.PointToClient(menuPoint)

NotifyIcon1.ContextMenu.Show(Me, menuPoint)
End Sub
<no****@meatonconsulting.comwrote in message
news:11*********************@q40g2000cwq.googlegro ups.com...
>I am using VB Net 2005 and want to use the notifyicon. I do not have a
form, only a class. I have no problems showing or modifying the
NotifyIcon, however, I am having a problem handling the click event. I
have tried unsuccessfully using AddHandler:

AddHandler nIcon.Click AddressOf nIcon_Click

Private Sub nIcon_Click(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("Click")
End Sub

Any help would be greatly appreciated.

Jan 4 '07 #2

Smokey Grindle wrote:
where is your add handler at? in the load?
Yes:
Public Sub New()
AddHandler nIcon.Click, AddressOf nIcon_Click
updateInt =
Registry.LocalMachine.OpenSubKey("Software\SI_Clie nt").GetValue("Update_int")
State()
End Sub
does it depend on another event happening first?
No. I would like the event to be raised at any point when the icon is
clicked. I am wondering if the State Sub has anything to do with the
handling. The program reads an update interval from the registry, and
then continuously processes and sleeps. Could it be that this is
stopping the event from being raised?

Public Sub State()
updateInt =
Registry.LocalMachine.OpenSubKey("Software\SI_Clie nt").GetValue("Update_int")
Dim bln As Boolean = True '(Always true for testing purposes
only...)
Do While bln
status =
Registry.LocalMachine.OpenSubKey("Software\SI_Clie nt").GetValue("color")

If status = "green" Then
SetGreen()
Else
SetRed()
End If

Thread.Sleep(updateInt)
Loop
End Sub

Jan 4 '07 #3
I think you are putting your entire application to thread sleep with that
thread.sleep there, you should do multi threading and put your "state" sub
in a seperate thread, so when paused it wont affect your UI thread, which I
think it is doing

<no****@meatonconsulting.comwrote in message
news:11**********************@6g2000cwy.googlegrou ps.com...
>
Smokey Grindle wrote:
where is your add handler at? in the load?
Yes:
Public Sub New()
AddHandler nIcon.Click, AddressOf nIcon_Click
updateInt =
Registry.LocalMachine.OpenSubKey("Software\SI_Clie nt").GetValue("Update_int")
State()
End Sub
does it depend on another event happening first?
No. I would like the event to be raised at any point when the icon is
clicked. I am wondering if the State Sub has anything to do with the
handling. The program reads an update interval from the registry, and
then continuously processes and sleeps. Could it be that this is
stopping the event from being raised?

Public Sub State()
updateInt =
Registry.LocalMachine.OpenSubKey("Software\SI_Clie nt").GetValue("Update_int")
Dim bln As Boolean = True '(Always true for testing purposes
only...)
Do While bln
status =
Registry.LocalMachine.OpenSubKey("Software\SI_Clie nt").GetValue("color")

If status = "green" Then
SetGreen()
Else
SetRed()
End If

Thread.Sleep(updateInt)
Loop
End Sub

Jan 4 '07 #4
Guess I just needed to talk it out... Thanks so much!
Smokey Grindle wrote:
I think you are putting your entire application to thread sleep with
that
thread.sleep there, you should do multi threading and put your "state"
sub
in a seperate thread, so when paused it wont affect your UI thread,
which I
think it is doing

Jan 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5449
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
8
4297
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
4
2552
by: hb | last post by:
Hi, When I add an asp:button (ex: id=btnLog) on home.aspx, I need to create btnLog_Click() event in home.aspx.cs, and also link this event and the button in OnInit() method by adding:...
3
2854
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes....
1
7588
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
0
5022
by: kyungdongkim | last post by:
Hi, I have a dynamically generated MenuStrip following this example: http://www.codeproject.com/useritems/Dynamic_MenuStrip.asp Basically the menu strip allows users to save and load reports. ...
0
1360
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
4
2874
by: bjjnova | last post by:
I need help dynamically resetting an event handler. I have a form with several buttons. I have intialized the Click event of a particular button thus on the form: _button_3.Click += new...
1
4276
by: \Ji Zhou [MSFT]\ | last post by:
Hello Jason, Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou and I will be working on this issue with you. I have tried to but cannot reproduce your issue on my side....
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.