Coding Thread, vb.net 2010 System Tray Icon and Popup Menu in Coding and Web Development; I recall doing NotifyIcon etc in vb6 but have not done much dot net programming / coding. I have seen ...
6th April 2011, 06:30 PM #1
vb.net 2010 System Tray Icon and Popup Menu
I recall doing NotifyIcon etc in vb6 but have not done much dot net programming / coding. I have seen the how to on codeproject.org but keep getting errors ref the Tray.Icon is not a member of Resources or something to that effect and some other errors ref creating the controls for menu strip etc
Any chance of a working example put together and zipped up as am getting a bit frustrated now.
6th April 2011, 07:20 PM #2
Only quick knocked up, (and 2008 but no real diff) as I don't have 2010 installed at home, but here you go:
(I assume your error was the fact you didn't add a NotifyIcon component? or something silly?)
Click button on form to hide form,
then in bar there's little runny man (or should be unless it broke in transit :P I know uncompiled projects don't like changing directories. It's just on my desktop (C) atm (Even if it breaks could just ninja form code))
Click him to reshow form etc etc
Last edited by Steve21; 6th April 2011 at 07:37 PM.
6th April 2011, 09:25 PM #3
I was hoping for a system tray icon, right click on system tray icon with 3 options
2. Log off
Click on Info and it opens the form with the username, ip address and stating network connected ( if not connected then ip address is blank or states invalid ip address and the latter option states disconnected )
Click on the Info form and it vanishes
Click on log off and it prompts if you want to log off and then logs off if yes is selected
Exit literally exists the app
I can do all the wmi stuff with ref to getting if its connected / disconnected , ip address, username etc but cant do the system tray icon with a popup menu
6th April 2011, 11:12 PM #4
The context menu strip still appears at the very top left of the screen, tried using e.x, e.y to get the screen co-ordinates and also tried another drawing function so it would draw it relevant to the screen co - ordinates etc but the menu still appears at the top left.
Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
'handling click event of the NotifyIcon
If e.Button = Windows.Forms.MouseButtons.Right Then
What control do I need to use to make a popup menu so when I right click on the notifyicon in the system tray it gives me a popup / context menu where I right clicked not miles away from where I am clicking.
7th April 2011, 12:06 AM #5
Quick note, Can you do me favour, and just make reply here. So tomorrow it'll popup in newposts for me :P Just incase I forgot, Will upload working example of what you want in morning, when in office.
7th April 2011, 12:32 AM #6
I've made a quick vid on how to do it. YouTube - How to add a Tray Icon in VS 2010. It's in C#, but the code is nearly directly comparable. I personally don't like using the context menu strip as it uses it's own graphics, the context menu control is the one that uses the Windows Theme. It's hidden by default.
7th April 2011, 08:52 AM #7
That did not help one bit as I do not know which things are vital in making the popup menu appear on the notify icon you just went through a whole bunch of stuff
Originally Posted by nickbro
went to form1 --> context menu --> set to popup ( this is what I named my context menu strip )
What does Initalise component do and why do I need that ??
I dont want to minimize the form, I want to totally hide it as in visible = false
Also how am I meant to close / destroy the notify icon and in which event ? Because when ever I stop the project form running its constantly leaving multiple icons in the system tray
Also I am getting an error on GetHostEntry when I use initialise component command ??
To get the hostname and ip address, am I better off just using wmi instead of using the inbuilt system.net.dns and gethostentry etc??
7th April 2011, 09:28 AM #8
I'm confused as to what the issue here is? To add a notifyIcon and contextMenuStrip to that notifyIcon is super simple. You add the notifyIcon to your form, then add a contextMenuStrip to it too, setting up your menu options. Then simply set the 'ContextMenuStrip' property of the notifyIcon to the contextMenuStrip icon you added.
7th April 2011, 10:20 AM #9
Initalise component runs the hidden VS code, don't worry about it.
Originally Posted by mac_shinobi
The Hide and Show functions are the same as setting visible = false | true
When you stop the project from the STOP icon in VS, it's doing a task kill event, which leaves the icon behind. If you right click and select close, it will remove the icon.
Don't use it then. I think Initalise component is a C# thing anyhow.
Try to avoid WMI where ever possible, it is buggy as anything. To get the IP you do Dns.GetHostEntry(Dns.GetHostName()). If you want the DNS name of the computer you just do Dns.GetHostName()
Thanks to nickbro from:
mac_shinobi (7th April 2011)
7th April 2011, 10:27 AM #10
Also What I'm doing on the resize event is sending the window to the tray icon, and removing it from the task bar. Because it's happening on the minimize event, you need to bring it back to a normal state when you show it again
7th April 2011, 10:30 AM #11
Try that Mr Mac, and if it's how you want I'll post code. (It's just the context how you wanted)
7th April 2011, 11:45 AM #12
If the above exe is uploaded inc source code The context menu works correctly so Id like that chunk of source, what you did etc, the minimizing the form is wrong but I can easily enough fix that.
Originally Posted by Steve21
Because I am using system.net.dns to get ip address / hostname etc, how does that work if say its a laptop which is physically connected ( ethernet cable ) and also by wireless G or N ??
Last edited by mac_shinobi; 7th April 2011 at 11:47 AM.
7th April 2011, 11:49 AM #13
I can't because I keep getting errors about can't convert to type string etc etc
Originally Posted by nickbro
7th April 2011, 11:52 AM #14
Did you read my bit above? It should be done via the designer, and is just a couple a couple of clicks rather than writing anything in the code?
Originally Posted by mac_shinobi
7th April 2011, 11:52 AM #15
Put .ToString() at the end
Also check out MSDN to find out what Properties you can use of them
By rush_tech in forum Windows
Last Post: 5th August 2013, 06:11 PM
By goodhead in forum Windows
Last Post: 19th December 2011, 10:44 AM
By weeb in forum Windows 7
Last Post: 24th January 2011, 06:57 PM
By Samson in forum Scripts
Last Post: 6th May 2008, 01:21 AM
By mac_shinobi in forum How do you do....it?
Last Post: 24th January 2006, 01:29 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)