Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

TrayIcon problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron M. Newman - 26 Aug 2006 21:56 GMT
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
Thom Little - 26 Aug 2006 23:29 GMT
In the form's properties I set ...

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

Signature

--  Thom Little  --  www.tlanet.net  --  Thom Little Associates, Ltd.
--

> Hi,
>
[quoted text clipped - 6 lines]
> thanks
> Ron
Philip Daniels - 27 Aug 2006 10:14 GMT
>Hi,
>
[quoted text clipped - 6 lines]
>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();
}

}
--
Philip Daniels
Ron M. Newman - 27 Aug 2006 17:54 GMT
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

>>Hi,
>>
[quoted text clipped - 48 lines]
> --
> Philip Daniels
Philip Daniels - 27 Aug 2006 18:38 GMT
>Hi - thanks, this makes much more sense.
>
[quoted text clipped - 5 lines]
>
>ron

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

Environment.Exit(0);

--
Philip Daniels
Chris Dunaway - 30 Aug 2006 21:27 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.