TrayIcon problem

R

Ron M. Newman

Hi,

I have an app whcih I want to be 100% tray icon, no pre-launched "main"
form. I don't know how to get rid of my main form. setting it to minimized
and show-taskbar=false doesn't help the ALT-TAB situation.

how do i make sure nothing is EVER visible other than my tray icon?

thanks
Ron
 
T

Thom Little

In the form's properties I set ...

Opacity = 0%
ShowInTaskbar = False
Size = 0,0
 
P

Philip Daniels

Hi,

I have an app whcih I want to be 100% tray icon, no pre-launched "main"
form. I don't know how to get rid of my main form. setting it to minimized
and show-taskbar=false doesn't help the ALT-TAB situation.

how do i make sure nothing is EVER visible other than my tray icon?

thanks
Ron

Ron, you don't need a main form at all in a WinForms app. Make a new
WinForms app, delete the form, and try this pseudo-code. You will need
to supply your own icon, menu etc., this won't compile out of the box
but should give you an idea of what is needed.



static class Program {

private static NotifyIcon m_Notify;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

// We don't need a form in order to create a notify icon.
m_Notify = new NotifyIcon();
m_Notify.Text = "Click me!";

// Must have an icon else we won't appear.
m_Notify.Icon = Properties.Resources.RonsIconHere;

// Handling a click is easy...
m_Notify.Click += new EventHandler(m_Notify_Click);

// Or a context menu...
//BuildContextMenu();

m_Notify.Visible = true;

// Start the windows message pump. The application will continue
// to run until Windows shuts down or your application is exited
// (you must provide the user with a way to do that).
Application.Run();
}

}
 
R

Ron M. Newman

Hi - thanks, this makes much more sense.

One question though, how do I "quit" from an application like this? where do
I inject the "exit" command if I have no main form to "Close()"

Let's say I had an event handler for double clicking the tray icon, I know
how to respond to that -- how do I close the app from there?

ron

Philip Daniels said:
Hi,

I have an app whcih I want to be 100% tray icon, no pre-launched "main"
form. I don't know how to get rid of my main form. setting it to minimized
and show-taskbar=false doesn't help the ALT-TAB situation.

how do i make sure nothing is EVER visible other than my tray icon?

thanks
Ron

Ron, you don't need a main form at all in a WinForms app. Make a new
WinForms app, delete the form, and try this pseudo-code. You will need
to supply your own icon, menu etc., this won't compile out of the box
but should give you an idea of what is needed.



static class Program {

private static NotifyIcon m_Notify;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

// We don't need a form in order to create a notify icon.
m_Notify = new NotifyIcon();
m_Notify.Text = "Click me!";

// Must have an icon else we won't appear.
m_Notify.Icon = Properties.Resources.RonsIconHere;

// Handling a click is easy...
m_Notify.Click += new EventHandler(m_Notify_Click);

// Or a context menu...
//BuildContextMenu();

m_Notify.Visible = true;

// Start the windows message pump. The application will continue
// to run until Windows shuts down or your application is exited
// (you must provide the user with a way to do that).
Application.Run();
}

}
 
P

Philip Daniels

Hi - thanks, this makes much more sense.

One question though, how do I "quit" from an application like this? where do
I inject the "exit" command if I have no main form to "Close()"

Let's say I had an event handler for double clicking the tray icon, I know
how to respond to that -- how do I close the app from there?

ron

Try this (rarely used from WinForms, but should do the job here):

Environment.Exit(0);
 
C

Chris Dunaway

Philip said:
Try this (rarely used from WinForms, but should do the job here):

Environment.Exit(0);

Actually, Application.Exit or Application.ExitThread might be more
appropriate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top