Solved

Forms pop-up at startup

Posted on 2003-11-06
8
818 Views
Last Modified: 2013-11-28
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!
0
Comment
Question by:DeuceEE
  • 4
  • 4
8 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9699633
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
 
LVL 1

Author Comment

by:DeuceEE
ID: 9699702
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
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9699729
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
 
LVL 1

Author Comment

by:DeuceEE
ID: 9699823
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 20

Accepted Solution

by:
TheAvenger earned 130 total points
ID: 9699851
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
 
LVL 1

Author Comment

by:DeuceEE
ID: 9699888
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
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9699915
You are welcome - whenever I can help
0
 
LVL 1

Author Comment

by:DeuceEE
ID: 9699937
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now