[RESOLVED] [1.0/1.1] Creating a toolbar menu for an application
Hi guys, another question. Is there any way I could create a tool bar icon similar to say msn so the user could click and could be presented with some options e.g. stop, re-start, start?
What I'm doing is similar to a watchdog type application where it simply runs in the background, has no GUI for user interaction. Also I cannot implement it as a service since of the unique requirements I have to cater for. I'm finished, but only one problem, there is no way for the user to turn it off apart from going in the Task Manager and manually shutting it down. So I was thinking about creating something similar to msn with an icon down at the task bar, and when you click, some options, stop, re-start etc. Could C Sharp handle this or is this way over C sharp capabilities?
Jennifer
Re: [1.0/1.1] Creating a toolbar menu for an application
No problems, just use a NotifyIcon component. It's very easy :)
If you have no GUI I am fairly sure you can do it all through code. Just not in a console app, as far as I know, but I guess you are not using a console either.
Re: [1.0/1.1] Creating a toolbar menu for an application
Really it is easy?? lol. could you send me a link to a good tutorial to use this? No i'm not using a console, i'm using an application.
Seems everything I could think about that I initialy thought C sharp cant handle it apparently could. Is there anything C sharp can't handle???
Jennifer Thanks.
Re: [1.0/1.1] Creating a toolbar menu for an application
The first thing to do, as always, is to go to MSDN and read about the NotifyIcon class.
Just create a form and add a NotifyIcon component to it in the designer. You can then add a ContextMenu with the desired options and assign it to the ContextMenu property of the NotifyIcon. You would set the Visible property of the NotifyIcon to True. You would also set the ShowInTaskbar property of the form to False and the WindowState to Minimized. That way there will be no initial evidence of your form. You still have to do one more thing though. You will still be able to Alt+Tab to the form this way so you have to set its Visible property to False. You cannot do that until after the Show event handler has completed though. You would use the Activated event like this:
Code:
private bool firstActivation = true;
private void Form1_Activated(object sender, EventArgs e)
{
if (this.firstActivation)
{
this.Hide();
this.firstActivation = false;
}
}
A couple of final things to note. This isn't really anything to do with C#. This is the functionality provided by the Framework class library. Also, the area that this icon appears in is officially called the notification area (hence the name NotifyIcon) and unoffically called the system tray, which is how everyone refers to it.
Re: [1.0/1.1] Creating a toolbar menu for an application
Thanks I got it to work. Your instructions are good. Thank you - Jennifer :thumb: