473,563 Members | 2,884 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(ByV al sender As Object, ByVal e As EventArgs)
MsgBox("Click")
End Sub

Any help would be greatly appreciated.

Jan 4 '07 #1
4 2101
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 InitializeConte xtMenu()
Dim menuList() As MenuItem = New MenuItem() _
{New MenuItem("Sign In"), New MenuItem("Get Help"), _
New MenuItem("Open" )}
Dim clickMenu As New ContextMenu(men uList)
NotifyIcon1.Con textMenu = clickMenu
End Sub
' When user clicks the left mouse button display the shortcut menu.
' Use the SystemInformati on.PrimaryMonit orMaximizedWind owSize property
' to place the menu at the lower corner of the screen.
Private Sub NotifyIcon1_Cli ck(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles NotifyIcon1.Cli ck

Dim windowSize As System.Drawing. Size = _
SystemInformati on.PrimaryMonit orMaximizedWind owSize
Dim menuPoint As System.Drawing. Point = New System.Drawing. Point _
(windowSize.Wid th - 180, windowSize.Heig ht - 5)
menuPoint = Me.PointToClien t(menuPoint)

NotifyIcon1.Con textMenu.Show(M e, menuPoint)
End Sub
<no****@meatonc onsulting.comwr ote in message
news:11******** *************@q 40g2000cwq.goog legroups.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(ByV al 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.LocalM achine.OpenSubK ey("Software\SI _Client").GetVa lue("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.LocalM achine.OpenSubK ey("Software\SI _Client").GetVa lue("Update_int ")
Dim bln As Boolean = True '(Always true for testing purposes
only...)
Do While bln
status =
Registry.LocalM achine.OpenSubK ey("Software\SI _Client").GetVa lue("color")

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

Thread.Sleep(up dateInt)
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****@meatonc onsulting.comwr ote in message
news:11******** **************@ 6g2000cwy.googl egroups.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.LocalM achine.OpenSubK ey("Software\SI _Client").GetVa lue("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.LocalM achine.OpenSubK ey("Software\SI _Client").GetVa lue("Update_int ")
Dim bln As Boolean = True '(Always true for testing purposes
only...)
Do While bln
status =
Registry.LocalM achine.OpenSubK ey("Software\SI _Client").GetVa lue("color")

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

Thread.Sleep(up dateInt)
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
5465
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 dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last...
8
4303
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender,...
4
2555
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: this.btnLog.Click +=new System.EventHandler(this.btnLog_Click); Now, I need to generate some asp:button dynamically in an asp:table, and assign the event...
3
2858
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. FindControl doesn't work, and the textboxes cannot be accessed using grid.Rows.Cells.Control. Can someone help? Thanks, Keith
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 usercontrol is a button and a label. Everytime the button is clicked a counter which is stored in the viewstate is increased and displayed in the...
0
5032
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. The Load menu is to list all the saved reports. I need to refresh the Load menu after a new report is saved. Any help is much appreciated! ...
0
1367
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 tabpanels such as:Catalog,Terms,SiteMap.ViewCart ,etc. All the jewellery Intro is in the Catalog panel. when I first click the Catalog panel it...
4
2877
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 EventHandler(the_controller.onButton3Click_NewEE); On the same form, I am establishing a property so that I can reset the Click event from another...
1
4282
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. From your codes, I think the logical is, every time the Timer's elapsed event fires, we call the Check_For_Version_Update() function. From the...
0
7664
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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 we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.