+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Creation icons in the Notification bar - VB.NET

  1. #1
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Creation icons in the Notification bar - VB.NET

    In your Notification bar you can found a lot of icons from different programs, some for just letting you open the program fast(by clicking or double-clicking the icon) while some has more functions in a menu(by right clicking the icon) but most programs with the icons have both. I will in this tutorial show how to add a icon like this and also how to add a menu to it.




    First we need to create an NotifyIcon, do that by dragging it from the toolbox and then name it exampleIcon. Change Text to "This is my Icon". We also need to set which icon it should use, if you want another one then your program has then you can choose it, otherwise we can use some code to copy the one that is used by the program itself.


    [highlight=VB.NET] Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    exampleIcon.Icon = Me.Icon
    End Sub[/highlight]


    As simple as that. So what it does is when the forms load we copy the forms icon to the NotifyIcon's icon. So now if you test your application an icon will pop up in the Notification Bar with the text "This is my Icon" and with the same icon as your program. But if you closes the application the icon still remains, this is because it don't updates the icons all the time, move your mouse over the icon and it will now update in realize it should be there and therefor disappear. To solve this problem we could add some more code to the program which makes the icon disappear when the form is closed.


    [highlight=VB.NET] Private Sub frmMain_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
    exampleIcon.Dispose()
    End Sub[/highlight]

    So when the form is disposed we also dispose the icon.



    But our icon doesn't currently do anything at all more then just "being there". We should add some code to make it show the form if we double clicks on the icon, to do this we need to do two things, we need to unminimize the form if it is minimized so the user can see it and also Activate it won't be covered by other programs. But when unminimizing the form it will automatically be Activated so we only need to Activate the form if it isn't minimized.




    [highlight=VB.NET] Private Sub exampleIcon_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles exampleIcon.MouseDoubleClick
    If Me.WindowState = FormWindowState.Minimized Then
    Me.WindowState = FormWindowState.Normal
    Else
    Me.Activate()
    End If
    End Sub[/highlight]








    BalloonTips


    We can also add something that is called BalloonTip, it's the bubbles that are showed from the icon sometimes. Remember that these things could be annoying for the user if done to much so think it through before using them. But I'll show how to do it of course. We will need to go back to the property window for the NotifyIcon to add the BalloonTip. Change the BalloonTipIcon to Info the BalloonTipText to "This could be annoying" and BalloonTipTitle to "Information". Now we've created the BalloonTip and only need to make it show. We need to use ShowBalloonTip to show the Tip. We now need to write how many milliseconds this Tip should be showed, to show how annoying it could be we adds it to the Load event of the form.



    [highlight=VB.NET] Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    exampleIcon.Icon = Me.Icon
    exampleIcon.ShowBalloonTip("3000")
    End Sub[/highlight]


    Note that even though I'm pointing out it could be annoying it don't have to be that if you use it in the right way, I just want to warn you from using it too much in the wrong situations.










    ContexMenuStrips


    Now there's time to add a menu, the menus is called ContexMenuStrips. Drag one from the toolbox onto your form and name it exampleStrip, when having the ContexMenuStrip selected we will see some boxes in top of the visual form. Here you can just type some text to make items to the menu. If you want to have a little more control you can go to properties and then edit Items, here you will have all options for the items. Now just create some items. If you want things to happen when you click on a menu you just add a click event to that one with the desired code.


    Now go back to the NotifyIcon and set the ContexMenuStrip property to the ContexMenuStrip(exampleStrip). Then it's time to test it, run your program and right click your icon, now the menu will appear. So that was mostly it, now you can create a NotifyIcon and use it to make your program easier to use. I hope you liked this one, Cya

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Creation icons in the Notification bar - VB.NET

    This is very handy to know. +rep!

  4. #3
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Creation icons in the Notification bar - VB.NET

    Quote Originally Posted by Jordan View Post
    This is very handy to know. +rep!
    Thanks But haven't received any +rep

  5. #4
    Join Date
    Jul 2006
    Posts
    16,494
    Blog Entries
    75
    Rep Power
    143

    Re: Creation icons in the Notification bar - VB.NET

    Nice +rep
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    Tareq is offline Newbie
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Re: Creation icons in the Notification bar - VB.NET

    Hi,

    Is there any way to make a context menu item default in the system tray of my own application ?

  7. #6
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: Creation icons in the Notification bar - VB.NET

    nice one .. i like it .. +rep

  8. #7
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Creation icons in the Notification bar - VB.NET

    this helped alot in my college work/revision, thanks!!

  9. #8
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: Creation icons in the Notification bar - VB.NET

    When I put in
    Code:
     exampleIcon.Icon = Me.Icon
    and run the program nothing pops up am I doing something wrong?
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

  10. #9
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Creation icons in the Notification bar - VB.NET

    You have to create the notify icon first, read the beginning of the second paragraph.

  11. #10
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: Creation icons in the Notification bar - VB.NET

    I did but it still doesn't do any thing.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Unhide Icons in win 7?
    By zeroradius in forum Computer Software/OS
    Replies: 4
    Last Post: 12-06-2011, 03:59 AM
  2. Tutorial: Simple Notification Tray Icon Part 1
    By PGP_Protector in forum CSharp Tutorials
    Replies: 2
    Last Post: 10-21-2010, 10:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

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