473,387 Members | 1,536 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.

Is this a safe way to hide the main form?

I'm writing a tray application and I of course want to hide the main form
when the appstarts. I've experimented with a couple of techniques to do
this, including setting Opacity to 0, but this seems a bit kludgy. I ended
up doing this:

static void Main()
{
new MyAppForm();
Application.Run();
}

This differs from a normal Main by calling the void version of the Run
method and moving the new call out as a separate statement. I haven't been
able to find any good description as to whether this is a safe thing to do.
It seems to work fine and my service behavs as expected, responding properly
to its context menu accesses. I like this better than setting Opacity to 0.
Another solution I experiented with was to use the normal Run call:

Application.Run(new MyAppForm());

and in the constructor of the main form call Hide(), but for some reason
this doesn't work. So, unless someone has a better solution or tells me that
I shouldn't the void Run call, I'll stick with doing it this way.

Peter Steele
CIENA Corp.
Nov 16 '05 #1
2 3621
So, if you're not ever going to show your main form, why don't you create a
console application? Or why don't you get rid of your main form altogether?

-vJ

"Peter Steele" <ps*****@ciena.com> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
I'm writing a tray application and I of course want to hide the main form
when the appstarts. I've experimented with a couple of techniques to do
this, including setting Opacity to 0, but this seems a bit kludgy. I ended
up doing this:

static void Main()
{
new MyAppForm();
Application.Run();
}

This differs from a normal Main by calling the void version of the Run
method and moving the new call out as a separate statement. I haven't been
able to find any good description as to whether this is a safe thing to do. It seems to work fine and my service behavs as expected, responding properly to its context menu accesses. I like this better than setting Opacity to 0. Another solution I experiented with was to use the normal Run call:

Application.Run(new MyAppForm());

and in the constructor of the main form call Hide(), but for some reason
this doesn't work. So, unless someone has a better solution or tells me that I shouldn't the void Run call, I'll stick with doing it this way.

Peter Steele
CIENA Corp.

Nov 16 '05 #2
Peter Steele wrote:
[...]

static void Main()
{
new MyAppForm();
Application.Run();
}

[...]


Check out this link:

http://msdn.microsoft.com/library/de...sinception.asp
- or -
http://makeashorterlink.com/?G1A022AB7

Side-note: should this be added to some faq?
Nov 16 '05 #3

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...
2
by: Peter Steele | last post by:
I'm writing a tray application and I of course want to hide the main form when the appstarts. I've experimented with a couple of techniques to do this, including setting Opacity to 0, but this...
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: 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...
2
by: gene kelley | last post by:
I have a dialog form, frmDetails, that is opened from the main form: frmDetails.ShowDialog() The only way I have provided to close this dialog is via the "X" button. If frmDetails is just...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
2
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, I've got a MAIN form, which I have a series of navigational buttons on. When I open a secondary form from that form, I'd like to be able to HIDE the original form. The reason is, if...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.