Forms pop-up at startup

Whenever I create a new form, it has to show, and there's no way to initialize it to be invisible.

I searched in MSDN, and found this article "Setting a Form to Be Invisible at Its Inception" which suggests that I create the form from within a startup module, but it still doesn't solve my problem.

The form I'm trying to show at startup is dynamically positioned, that means I want to set its position at runtime -- so I want it to be invisible until I reposition it, otherwise it pops up in the middle of the screen for a couple of seconds and then repositions itself, which is what no one ever needs. In other words, my form sticks itself to the right side of the screen, which can be different everytime I run it (I could be on 800x600 or even 1280x1024).

And what if I want it to become a tray icon (aka. notify icon) and pops up just when the user clicks the tray icon, it also pops up and then disappears.

Anyone faces the same problem? It's really annoying, I can't believe I want to go back to VB6 for this reason!
LVL 1
DeuceEEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheAvengerCommented:
I made something like this: in OnLoad I set the size of the form to (0,0). So the form is not really visible. Then when you finish repositioning the form, you can show it in the right place.

Another trick it so catch the VisibleChanged event and in its start wait until the operations you need are done, reposition the form and then exit the event handler. It is important to do these operations it only in the beginning of your application
0
DeuceEEAuthor Commented:
Funny you mentioned those suggestions, because they were the workarounds I was working on, until it became very tiring.

So, is this some sort of a bug in C# or something? Do I have to do this everytime I want to "initialize" Visible to false? There's nothing else to do?!
0
TheAvengerCommented:
Actually I think you can make it another way: go to the main method of the form and change the call to Application.Run method. you can do several things:

1. Create the form, set its position and then call the Application.Run method
2. Change the Application.Run call so that it does not take the form as a parameter. Then you have to create a new form in your main method, adjust everything there and show the form when you need it.

In option 2 you will probably have to manage manually the lifetime of the application.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

DeuceEEAuthor Commented:
Application.Run() is a very good idea.

But, unfortunately, it wouldn't help.
In my project, I added a new form (e.g. form2) and within my frmMain_Load event, I created a new instance of form2, and it did exactly the same thing, pops up before repositioning. That implies that even if it was the main form, it would still act the same way.


Why am I having a feeling that this problem exists within the compiler or something? It's not part of a code that we can change.
(I just did some debugging and tracking, this is what I found)
The line:
frmMain fm = new frmMain();
creates the form, but it's not yet shown.
I change the location, I check the Location property, it holds the location I want.
Just when I change visiblity to true, I check the Location property, it changed "automatically" to the "Windows Default" or whatever, it just pops up, then after it's visually loaded, it changes back to the location I want.

So, even if I change the location of the form before I make it visible, it loads itself like it has a mind of its own, and then it goes back to normal.


Try some debugging you'll find what I say true. I'm telling you, either we're missing something, or there's a bug in C#.
0
TheAvengerCommented:
Actually I tried this one in my OnLoad method and it works pretty fine, no blinking or anything:

this.StartPosition = FormStartPosition.Manual;
this.Location = new Point (0, 0);
this.Size = new Size (100, 100);

You can set also the start position directly from the designer, as well as the location and size. So it works actually in the easiest possible way but you have to set the start position to manual
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DeuceEEAuthor Commented:
THAT's why!


Now it all makes sense.
I once changed it to Manual, but apparently I did something and it screwed everything up, so I thought Manual had something to do with it and never thought about using it again.



Thank you, thank you!
Here are your points! Thanks for your time.
0
TheAvengerCommented:
You are welcome - whenever I can help
0
DeuceEEAuthor Commented:
Maybe you could help me with this problem, too? http://www.experts-exchange.com/Programming/Q_20790501.html

That'd be great, being the "Fearured Expert" you are. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Internet Marketing

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.