Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to hide the windows form application on page load.

I tried the below snippet on page load :-

this.hide();


But it doesn't work and my application still able to see. The Same code I wrote in click event. It works.
Can Anyone tell me why this happens and also can give me the snippet to hide the application on page load
Posted

Why?
If you don't want your application visible, then don't show a form at all - but that's kinda unusual, and you might be better writing a service instead.

You can't Hide the form in the Load event anyway, because the Show instruction is given after the Load event is completed - so it would hide what hasn;t been shown, and the display it anyway.

Why do you want to do this? Hiding a form is normally pretty odd - there may be a better way to do what you are trying to achieve.
 
Share this answer
 
Comments
binadi007 7-Apr-14 5:39am    
the thing is I saved A previous state if it is set hide in previous state than on the start form this previous state value chaeck and according to it , it will hide
binadi007 7-Apr-14 5:41am    
And one more thing the form will again show on pressing the shortcut key
OriginalGriff 7-Apr-14 5:53am    
What shortcut key? A form can't get keyboard input while it's hidden...
OriginalGriff 7-Apr-14 5:53am    
OK - set the default state to Minimized, then handle the Shown event.
You can call either the Hide or set
WindowState = FormWindowState.Normal;
in that and it will work fine.
(If you don't start minimized, then the form and all it's controls will "flash" into existence on the screen and then disappear)
binadi007 7-Apr-14 5:55am    
can u help by snippet.....coz i don't get ur point
Try this.Hide in form activated event.

C#
 private void Form1_Activated(object sender, EventArgs e)
        {
            this.Hide();
        }

//This code initialize method
private void InitializeComponent()
{
 this.Activated += new System.EventHandler(this.Form1_Activated);
}
 
Share this answer
 
v2
Comments
binadi007 7-Apr-14 6:19am    
plz give the snippet
ArunRajendra 7-Apr-14 6:40am    
See the updated solution.
OriginalGriff 7-Apr-14 6:58am    
Reason for my vote of one: You do realize that the Form.Activated event is triggered every time the form gets the focus? For example, if you unhide the form, it will give an Activated event. If you switch back to the form after using a different application (or even a different form or message box in the same application)

So every time the user tries to use the form, it will hide itself from him again... :doh:
Please, try to test your solutions before you post them...

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