473,396 Members | 1,767 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,396 software developers and data experts.

Hide Form on Startup

Hi,
I have an application which, when running, is to be seen only in the system
tray as a right-clickable icon.

However I want the main Form window itself to immediately disappear without
having to be minimized.

I have tried putting
this.Hide();
in the Load method, but that doesn't work (the form still comes up and needs
to be minimized).
I've also tried it (the Hide() code) before and after the
InitializeComponent() call, but that didn't help either.

What is the correct technique to make an application disappear without
having to be automatically minimized?

Thank-you for your help!

Regards,
Raj
Jul 15 '06 #1
3 3311
"Raj Wall" <me********@nospam.nospamwrote:
I have an application which, when running, is to be seen only in the system
tray as a right-clickable icon.

However I want the main Form window itself to immediately disappear without
having to be minimized.
Probably the easiest way is to not pass it to the Application.Run()
method. Here's a simple windows application which toggles the visibility
of a form with clicking on the icon:

---8<---
using System;
using System.Windows.Forms;
using System.Drawing;

class App
{
static void Main()
{
NotifyIcon icon = new NotifyIcon();
icon.Text = "Foo";
icon.Icon = SystemIcons.Exclamation;
icon.Visible = true;

Form form = new Form();
icon.MouseClick += delegate
{
if (form.Visible)
form.Hide();
else
form.Show();
};

form.FormClosed += delegate
{
icon.Dispose();
Application.Exit();
};

Application.Run();
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/
Jul 15 '06 #2
Barry, hi,

Thanks, that put me on the right track.
I moved my menuItem code, etc out of the Load method and into the form
creation method. I also found the following MSDN pages helpful:
http://msdn.microsoft.com/library/de...sinception.asp
and
http://msdn.microsoft.com/library/de...anceofform.asp

Thanks again for your help!

Regards,
Raj
"Barry Kelly" <ba***********@gmail.comwrote in message
news:40********************************@4ax.com...
"Raj Wall" <me********@nospam.nospamwrote:
>I have an application which, when running, is to be seen only in the
system
tray as a right-clickable icon.

However I want the main Form window itself to immediately disappear
without
having to be minimized.

Probably the easiest way is to not pass it to the Application.Run()
method. Here's a simple windows application which toggles the visibility
of a form with clicking on the icon:

---8<---
using System;
using System.Windows.Forms;
using System.Drawing;

class App
{
static void Main()
{
NotifyIcon icon = new NotifyIcon();
icon.Text = "Foo";
icon.Icon = SystemIcons.Exclamation;
icon.Visible = true;

Form form = new Form();
icon.MouseClick += delegate
{
if (form.Visible)
form.Hide();
else
form.Show();
};

form.FormClosed += delegate
{
icon.Dispose();
Application.Exit();
};

Application.Run();
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/

Jul 15 '06 #3
Another solution that can be run in the form constructor/load event:

this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;

If you can't justify a full form GUI but find a notifyicon sufficient!

-Brandon

"Raj Wall" wrote:
Barry, hi,

Thanks, that put me on the right track.
I moved my menuItem code, etc out of the Load method and into the form
creation method. I also found the following MSDN pages helpful:
http://msdn.microsoft.com/library/de...sinception.asp
and
http://msdn.microsoft.com/library/de...anceofform.asp

Thanks again for your help!

Regards,
Raj
"Barry Kelly" <ba***********@gmail.comwrote in message
news:40********************************@4ax.com...
"Raj Wall" <me********@nospam.nospamwrote:
I have an application which, when running, is to be seen only in the
system
tray as a right-clickable icon.

However I want the main Form window itself to immediately disappear
without
having to be minimized.
Probably the easiest way is to not pass it to the Application.Run()
method. Here's a simple windows application which toggles the visibility
of a form with clicking on the icon:

---8<---
using System;
using System.Windows.Forms;
using System.Drawing;

class App
{
static void Main()
{
NotifyIcon icon = new NotifyIcon();
icon.Text = "Foo";
icon.Icon = SystemIcons.Exclamation;
icon.Visible = true;

Form form = new Form();
icon.MouseClick += delegate
{
if (form.Visible)
form.Hide();
else
form.Show();
};

form.FormClosed += delegate
{
icon.Dispose();
Application.Exit();
};

Application.Run();
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/


Jul 25 '06 #4

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

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
9
by: Mark | last post by:
Hi All, I am trying to use the function found on the MVP site http://www.mvps.org/access/api/api0019.htm to hide the Access window. I must be missing something as I keep getting an error message:...
2
by: amil [c#newbie] | last post by:
Hi all, I am using the Notify Icon sample that came with .Net Docs and was able to run it. However, I want to start the form as minimized. I have the ShowInTaskbar = false and in the this is...
5
by: Kirk Graves | last post by:
Can anyone tell me why this code does not work? Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Hide() End Sub If runs, but the...
4
by: Matthew | last post by:
The following code does not hide the form. Any ideas why? Also, is there a workaround? I have VB.NET 2003. I have a system tray icon, and want to have that be the only thing showing when the...
4
by: BrianDH | last post by:
Hi I have an application with 3 windows forms. One of which I load at startup but hide, then show/hide based on users click. How can I test to see if the windows is hidden, or is at the moment...
3
by: Gil | last post by:
on start up i have a form that opens but i want it to stay hidden. i tried a few things so far and i had no luck. i did : Private Sub Form_Load() me.visible = false End Sub Private Sub...
6
by: MJB | last post by:
I have an application that I need to hide at startup in the system tray. I found this article on how to do it:...
11
by: Nick 'The database Guy' | last post by:
Hi People, How do you go about hiding the database window. The reason for doing this is that sometimes have to manually add data to tables. I have a fully interatctive menu system from which...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.