+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
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 ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361

    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.

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    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?)

    WindowsApplication1.zip

    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

    Any use?

    Steve
    Last edited by Steve21; 6th April 2011 at 06:37 PM.

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    I was hoping for a system tray icon, right click on system tray icon with 3 options

    1. Info
    2. Log off
    3. Exit

    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

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Code:
       
     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
                popup.Show(e.Location)
            End If
    
        End Sub
    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.

    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.

  5. #5

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    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.

    Steve

  6. #6
    nickbro's Avatar
    Join Date
    Jul 2010
    Location
    Gilwern, Wales
    Posts
    3,471
    Thank Post
    37
    Thanked 483 Times in 415 Posts
    Rep Power
    109
    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.

  7. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by nickbro View Post
    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.
    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

    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??

  8. #8

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,528
    Thank Post
    513
    Thanked 2,406 Times in 1,862 Posts
    Blog Entries
    24
    Rep Power
    822
    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.

  9. #9
    nickbro's Avatar
    Join Date
    Jul 2010
    Location
    Gilwern, Wales
    Posts
    3,471
    Thank Post
    37
    Thanked 483 Times in 415 Posts
    Rep Power
    109
    Quote Originally Posted by mac_shinobi View Post
    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

    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??
    Initalise component runs the hidden VS code, don't worry about it.

    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()

  10. Thanks to nickbro from:

    mac_shinobi (7th April 2011)

  11. #10
    nickbro's Avatar
    Join Date
    Jul 2010
    Location
    Gilwern, Wales
    Posts
    3,471
    Thank Post
    37
    Thanked 483 Times in 415 Posts
    Rep Power
    109
    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

  12. #11

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Try that Mr Mac, and if it's how you want I'll post code. (It's just the context how you wanted)

    WindowsApplication2.zip

    Steve

  13. #12

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by Steve21 View Post
    Try that Mr Mac, and if it's how you want I'll post code. (It's just the context how you wanted)

    WindowsApplication2.zip

    Steve
    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.

    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 10:47 AM.

  14. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by nickbro View Post
    Initalise component runs the hidden VS code, don't worry about it.

    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()
    I can't because I keep getting errors about can't convert to type string etc etc

  15. #14

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,528
    Thank Post
    513
    Thanked 2,406 Times in 1,862 Posts
    Blog Entries
    24
    Rep Power
    822
    Quote Originally Posted by mac_shinobi View Post
    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.

    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 ??
    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?

  16. #15
    nickbro's Avatar
    Join Date
    Jul 2010
    Location
    Gilwern, Wales
    Posts
    3,471
    Thank Post
    37
    Thanked 483 Times in 415 Posts
    Rep Power
    109
    Put .ToString() at the end

    Also check out MSDN to find out what Properties you can use of them

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Nvidia Tray Icon
    By rush_tech in forum Windows
    Replies: 8
    Last Post: 5th August 2013, 05:11 PM
  2. wireless system tray icon
    By goodhead in forum Windows
    Replies: 8
    Last Post: 19th December 2011, 09:44 AM
  3. Replies: 0
    Last Post: 24th January 2011, 05:57 PM
  4. VBS System Tray popup
    By Samson in forum Scripts
    Replies: 7
    Last Post: 6th May 2008, 12:21 AM
  5. Close Tray and Eject Tray in Right context menu ?
    By mac_shinobi in forum How do you do....it?
    Replies: 2
    Last Post: 24th January 2006, 12:29 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •