+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
Coding Thread, vb.net 2010 System Tray Icon and Popup Menu in Coding and Web Development; Ok full code enclosed (Not sure where you'll try to run it from but I'm in N drive so it ...
  1. #16

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Ok full code enclosed (Not sure where you'll try to run it from but I'm in N drive so it might emo, but you can view form1.vb as it's all in there anyway even if project wont run)

    WindowsApplication2.zip

    (From Scratch)
    Step 1:
    Add ContextMenu and NotifyIcon from Toolbox (I left as default names)

    Step 2:
    In form load, Link Notifyicon to the menu (so when you right click it it appears near etc)
    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
            'Links menu to the Icon (aka, why yours was miles away)
        End Sub
    Step 3:
    Link event of clicking Icon to menu showing
    Code:
      Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
            If e.Button = MouseButtons.Right Then NotifyIcon1.ContextMenuStrip.Show()
            'Shows menu when Icon right clicked
        End Sub
    Step 4:
    Add menu items (Click on contextmenu item on form design page), Right click and edit items (add menu items)

    Step 5:
    Link commands/subs to clicks
    Code:
        Private Sub InfoMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InfoMenu.Click
            MsgBox("You clicked Info")
            'When Info clicked
        End Sub

    If the default project works ignore my waffle But I know when I tried it at home, it emo'd as my home pc is C:\ (obviously) and work one is N:\ :P

    Any problems shout etc,

    (ps, off topic but anyone knows how to disable quotes popping up as huge AMG ALERTS on edugeek?)

    Steve
    Last edited by Steve21; 7th April 2011 at 10:56 AM.

  2. Thanks to Steve21 from:

    mac_shinobi (7th April 2011)

  3. #17
    nickbro's Avatar
    Join Date
    Jul 2010
    Location
    Gilwern, Wales
    Posts
    3,560
    Thank Post
    38
    Thanked 507 Times in 437 Posts
    Rep Power
    114
    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 ??
    This is the code I use in HAP+ to get the IP address(es)

    Code:
                    foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                        if (ip.ToString().Contains(".")) { ip1 = ip.ToString(); break; }

  4. #18
    nickbro's Avatar
    Join Date
    Jul 2010
    Location
    Gilwern, Wales
    Posts
    3,560
    Thank Post
    38
    Thanked 507 Times in 437 Posts
    Rep Power
    114
    Quote Originally Posted by nickbro View Post
    Put .ToString() at the end

    Also check out MSDN to find out what Properties you can use of them
    Code:
                    foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                        if (ip.ToString().Contains(".")) { ip1 = ip.ToString(); break; }
    VB
    Code:
    For Each ip As IPAddress In Dns.GetHostEntry(Dns.GetHostName()).AddressList    
           If ip.ToString().Contains(".") Then
                ip1 = ip.ToString()
                Exit For     
           End If 
    Next

  5. Thanks to nickbro from:

    mac_shinobi (7th April 2011)

  6. #19

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,796
    Thank Post
    3,306
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365
    what is the safest method of logging off, I used to use WMI but you are stating that this is a messy method / means of logging off.

    The only other way is to use the process.start() method and to use the shutdown with relevant switches or rundll ??

    This is what I have so far, waiting on confirmation on the best method to log off but as far as the form is concerned ( might be messy ) but functionality assuming it does the same as what it did when I was running it, seems to work, obviously buggy
    Attached Files Attached Files
    Last edited by mac_shinobi; 11th April 2011 at 03:01 PM.

  7. #20

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by mac_shinobi View Post
    what is the safest method of logging off, I used to use WMI but you are stating that this is a messy method / means of logging off.

    The only other way is to use the process.start() method and to use the shutdown with relevant switches or rundll ??

    This is what I have so far, waiting on confirmation on the best method to log off but as far as the form is concerned ( might be messy ) but functionality assuming it does the same as what it did when I was running it, seems to work, obviously buggy
    WMI is fine, there are some buggy versions etc, but lots of programs use it with no issues.

    Btw, There's a much easier method of username if you're intested.

    ENVIRONMENT.USERNAME works fine assuming it's run as user, and not service/domain account etc. No imports etc, but only an idea :P Both ways work end of day.

    Other log off options:

    (Start process as you mentioned) System.Diagnostics.Process.Start("shutdown", "-l -t 00") (Can have issues based on OS etc)
    (Windows API) ExitWindowsEx(EWX_LogOff, 0&) (May need premissions) e.g. ExitWindows(RestartOptions.LogOff, True)
    Shell commands (Similar to the processes)
    Win32Shutdown Method (But if you don't want WMI, can't really use)


    Personally WMI is wonderful, and works for many many MANY things. Shouldn't discount it so quickly, but then opinions I guess :P End of day, Pick one you like, understand and makes it easier for you!

    Steve

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

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
  •