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 :)
Creation icons in the Notification bar - VB.NET
Started by Vswe, Nov 11 2009 03:48 PM
14 replies to this topic
#1
Posted 11 November 2009 - 03:48 PM
|
|
|
#2
Guest_Jordan_*
Posted 12 November 2009 - 06:06 AM
Guest_Jordan_*
This is very handy to know. +rep!
#3
Posted 12 November 2009 - 06:12 AM
Jordan said:
This is very handy to know. +rep!
Thanks :) But haven't received any +rep :P
#4
Posted 13 November 2009 - 08:10 AM
#5
Posted 23 November 2009 - 10:06 PM
Hi,
Is there any way to make a context menu item default in the system tray of my own application ?
Is there any way to make a context menu item default in the system tray of my own application ?
#6
Posted 28 November 2009 - 02:37 AM
nice one .. i like it :) .. +rep
#7
Posted 15 December 2009 - 02:48 PM
this helped alot in my college work/revision, thanks!!
#8
Posted 31 December 2009 - 09:57 AM
When I put in
exampleIcon.Icon = Me.Iconand run the program nothing pops up am I doing something wrong?
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#9
Posted 31 December 2009 - 02:00 PM
You have to create the notify icon first, read the beginning of the second paragraph.
#10
Posted 31 December 2009 - 02:27 PM
I did but it still doesn't do any thing.:confused:
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#11
Posted 01 January 2010 - 03:51 AM
What version of VB are you using?
#12
Posted 01 January 2010 - 07:16 AM
Microsoft Visual Basic 2008 Express Edition.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.


Sign In
Create Account


Back to top










