Solved

Forms pop-up at startup

Posted on 2003-11-06
8
819 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
An overview of how to create reports in Adobe Analytics (formerly Omniture Site Catalyst) using pageNames, events, eVars and props. This video will show you how to install the Omniture Debugger tool so can see (and test) what is being passed int…

929 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

12 Experts available now in Live!

Get 1:1 Help Now