Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Could you please explain to me what really happened with my code to do even the easiest thing that everyone can think of. I simply place the call "Hide()" in the body of the method encapsulated by the form load eventhandler. So when the form is loaded, it should hide, but it doesn't. I can't understand what hell it is, a rare bug from Visual Express 2008? Of course, if I put "hide()" into a method encapsulated by other event handlers such as doubleclick... it will work normally.
Any ideas please!
Thank you so much!
Posted

hide() put in Form Activated event. On Load its not work.
 
Share this answer
 
Comments
[no name] 7-Sep-11 17:09pm    
Thank you! What a great suggestion!
divesh12 7-Sep-11 17:23pm    
welcome
When a form is shown (you do call form.show, don't you?) the form is first loaded and after that it's shown which basically means that visible is set to true. So even if you hide (which actually sets the visible to false) the form in the load event the setting won't remain.

If you don't actually want to show the form yet, then I suggest that you don't call the Show method at this point. If you have some code you want to execute, create a new method and move the code into that method from the load event handler. After instantiating the form, call this new method. This way the form won't be shown at all until you later call Show at some point.
 
Share this answer
 
Is this the main form for the application? If so, you want to change its initial WindowState.[^]

If it's an additional form in an application, you're likely changing the form's state before it will have any impact. See Order of Events in Windows Forms.[^] and Windows Forms Events Lifecycle.[^]

In other words when the form's OnLoad method is called, it is already not visible, so calling Hide() or setting Visible=false may have no effect.
 
Share this answer
 
Comments
[no name] 7-Sep-11 16:55pm    
Yes. I have mentioned my main form. As you suggested, I changed the windowstate to minimized, and no need to add any code. It seems that the WindowState property will be assigned with the preset value right after the load method is finished. That's why thousands of calls to Hide() in the load method couldn't change the thing.
It differs too much from vb6.
Thank you so much!
Yvan Rodrigues 7-Sep-11 20:10pm    
You're welcome!
I think I know what you are saying. You may need a postback in order for the server to rewrite the html as hidden. You can do this by adding
AutoPostBack="true"
Some controls, like buttons, already do a postback so this is not needed.
 
Share this answer
 
Comments
Yvan Rodrigues 7-Sep-11 16:42pm    
WinForms, not Web Forms.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900