|
-
July 21st, 2005, 12:05 PM
#1
System Tray Application
I want to create an application that will start off in the system tray without any initial form being displayed. The problem is that I can't seem to create such an application without including a NotifyIcon control on a form.
Isn't there any way to start an application in the system tray without the use of a form? Obviously I could just create an invisible form and have the NotifyIcon control on there but it seems a little unnecessary. Isn't there any other way?
-
July 22nd, 2005, 01:57 AM
#2
Re: System Tray Application
hi there,
I'm not sure if this is what you are looking for but if you put this in your Main() method, it should work...
Code:
NotifyIcon tray = new NotifyIcon();
// Used to grab the embedded bitmap
System.Reflection.Assembly assembly =
System.Reflection.Assembly.GetCallingAssembly();
// The bitmap
Bitmap trayBitmap = (Bitmap)Bitmap.FromStream
(assembly.GetManifestResourceStream("KeyStroke.MacJournal.ico"));
// Convert Bitmap to Icon
Icon trayIcon = Icon.FromHandle(trayBitmap.GetHicon());
tray.DoubleClick += new EventHandler(tray_DoubleClick);
tray.Icon = trayIcon;
trayIcon = null;
tray.Visible = true;
while(true)
{
Application.DoEvents();
}
You could then use something like a Context Menu to add a menu to your tray application and use the double click event to show the form, which would be something like:
Code:
private static void tray_DoubleClick(object sender, EventArgs e)
{
// Fire a new instance main form
Form1 mainForm = new Form1();
mainForm.Show();
// Hide the tray Icon
((NotifyIcon)sender).Visible = false;
}
-
March 3rd, 2008, 04:01 AM
#3
Re: System Tray Application
When the form first Loads, is there an alternate way of hiding the form, because
Application.DoEvents();
causes unwanted outcome when responding to user events...
this.Hide();
doesn't work, so
How else can i just hide the form from the users eyes???
Rate this post if you found it useful!
10X, gilly914
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|