473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems hiding the main form and displaying only a tray icon

I want my application to run most of the time as just an notify icon
visible in the system tray, with some dialogs windows that open if the user
selects an option from the context menu on the tray icon. I've had a look at
the example on code project that creates an application that runs in the
system tray:

http://www.codeproject.com/csharp/de...il_checker.asp

So I copied how the above article sets up the main form: the form's
FormBorderStyle to none, set it to minizied, disable the titlebar controls
(maximize, minimize, close etc). It was all fine until I noticed that the
form was visible in the Alt-Tab menu and once you had alt-tabbed to it there
was no way of hiding it again :(

After a bit of googling I discover if I set the Form's FormBorderStyle to
FixedToolWindow then it was no longer visible in the Alt-Tab menu, result!
But today I have noticed that now I can no longer minimize or hide the form
it appears as a minizied tool window in the bottom left of my desktop when
the application is running and even worse if the user double clicks on the
title bar the window expands to its normal size, apart from the form is
empty and there's no way to minimize it again!

Anyone got any ideas as to how to completely hide form so its not visible as
a window on the taskbar or on the alt-tab menu? All I want is my
application's icon in the system tray while its running and a context menu
for the icon. I don't really need the main form at all!

Cheers,

DanielB
Nov 16 '05 #1
7 6817
Danielb <Da*****@nospam.net> wrote:
Anyone got any ideas as to how to completely hide form so its not visible as
a window on the taskbar or on the alt-tab menu?


Have you read the following? http://tinyurl.com/3lh6
Nov 16 '05 #2
Thats interesting, but I'm still confused. As all I want my app to do is
display a notify icon and a context menu for it, I already have options
dialogs that I create in response to the user selecting options on the
context menu. I don't want a main form at all but that link seems to imply
that I will need the unused main form?

The annoying thing is that making a form invisible is easy by setting
FormBorderStyle to None and setting the window to minizied. There just does
not seem an easy way to prevent it from being selectible on the Alt-Tab menu
(that I know of) without setting FormBorderStyle to FixedToolWindow which
would then seem to prevent it from being hidden when its 'minized'.

"C# Learner" <cs****@learner.here> wrote in message
news:br***************@csharp.learner...
Danielb <Da*****@nospam.net> wrote:
Anyone got any ideas as to how to completely hide form so its not visible
as
a window on the taskbar or on the alt-tab menu?


Have you read the following? http://tinyurl.com/3lh6

Nov 16 '05 #3
Why have a main form at all?

I've never really understood why so many people go to such lengths to have a
hidden main form and try to keep it invisible, rather than going for the
much simpler expedient of not using a main form at all.

Windows Forms doesn't require you to have a main form. If you just start
the app up like this:

Application.Run();

i.e. you don't pass in a form, then there is no main form. This means you
don't need to worry about it appearing in the Alt-Tab list - something
that's not there isn't going to appear!

So all you need to do is make sure you add the notify icon to the
notification area before you call Application.Run.

You'll also need to work out how you're going to shut down. If you don't
have a main form, the application will run until you call Application.Exit.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

"Danielb" <Da*****@nospam.net> wrote in message
news:30*************@uni-berlin.de...
I want my application to run most of the time as just an notify icon
visible in the system tray, with some dialogs windows that open if the
user selects an option from the context menu on the tray icon. I've had a
look at the example on code project that creates an application that runs
in the system tray:

http://www.codeproject.com/csharp/de...il_checker.asp

So I copied how the above article sets up the main form: the form's
FormBorderStyle to none, set it to minizied, disable the titlebar controls
(maximize, minimize, close etc). It was all fine until I noticed that the
form was visible in the Alt-Tab menu and once you had alt-tabbed to it
there was no way of hiding it again :(

After a bit of googling I discover if I set the Form's FormBorderStyle to
FixedToolWindow then it was no longer visible in the Alt-Tab menu, result!
But today I have noticed that now I can no longer minimize or hide the
form it appears as a minizied tool window in the bottom left of my desktop
when the application is running and even worse if the user double clicks
on the title bar the window expands to its normal size, apart from the
form is empty and there's no way to minimize it again!

Anyone got any ideas as to how to completely hide form so its not visible
as a window on the taskbar or on the alt-tab menu? All I want is my
application's icon in the system tray while its running and a context menu
for the icon. I don't really need the main form at all!

Cheers,

DanielB

Nov 16 '05 #4
"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> wrote:
Windows Forms doesn't require you to have a main form.


But doesn't a system tray icon require a window associated with it? It's
been a long time but I think I remember this being the case with Win32
windows, and if so, it's most likely the same situation for WinForms.
Nov 16 '05 #5
Nope.

It works just fine without a main form. Just tried it now.

Windows Forms creates hidden windows. So it it is necessary to have a
window in order to add a notify icon, maybe it's using one of these hidden
windows. You certainly don't need to create a Form object in order to have
your notify icon show up and respond to menu clicks.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

"C# Learner" wrote:
"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> wrote:
Windows Forms doesn't require you to have a main form.


But doesn't a system tray icon require a window associated with it? It's
been a long time but I think I remember this being the case with Win32
windows, and if so, it's most likely the same situation for WinForms.

Nov 16 '05 #6
The idea of not using a Form but rather managing the NotifyIcon
yourself is smart. BUT, if you dont use a Form, you cant use the
Designer to add resources (icons, wave files, etc.) to the project. How
do you get around this?

I want to use your non-form approach, but then how do I add an icon
resource into the project? I cant edit the resx file myself because you
need to serialise the icon to base64 and I dont know how to do that.

Nov 16 '05 #7
Oh and simply setting the resource to "embedded resource" isnt good
enough. That doesnt actually add the resource to the project so I can
get at it via the ResourceManager using some name. It doesnt embed it
at all if the main class is not a Form? What is wrong here?

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter Steele | last post by:
I created a tray application and everything works as expected when I run it under Windows XP. However, when I try the application on a PC running Windows NT, the main application form is visible as...
4
by: kurotsuke | last post by:
How can I hide a Form (instead of having it reduced to the taskbar) when the minimize button is pressed in C# (there's an icon in the tray bar)? I added the code protected override void...
8
by: Michael Rich | last post by:
I am writing a program that primaryly runs in the system tray. When the program starts, I would like to hide the main form and only show the tray icon. in the Form Load event I set Me.Visible =...
4
by: Tony Vitonis | last post by:
Hello. I've written an app that I want to "live" in the system tray. I want it to start up with just a tray icon showing, and if the user selects "Settings..." from the icon's context menu, to...
0
by: kapcreations | last post by:
I have a system tray app which gets the status of a windows service, and displays the appropriate icon for the status of the service in the systray. the problem I am having is the icon disapears...
1
by: Thief_ | last post by:
I have two projects in one solution: a.. Outlook Monitor b.. Tray Notification Both contain a form called "Form1.vb". How do I reference "Outlook Monitor"'s Form1 from "Tray Notification"'s...
0
by: Gary Brown | last post by:
Hi, I have a simple application that displays word-definition pairs at the top of the screen. How do I keep its icon from displaying in the Alt-TAB menu (what is it called?)? It runs with a...
5
by: Wilfried Mestdagh | last post by:
Hi, I have an application with a main form, but I want to hide it as fast as possible. Seems the only way to not show a single flicker is setting Opacity = 0 in the constructor, and Visible =...
2
by: jp2group | last post by:
I have a Main Form that hides in the Task Bar Tray as an Icon until one of the Tray Icon's Menu Items is selected. (think of your antivirus program running there) The program starts up fine and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.