<p>I have an application with one form in it, and on the Load method I need to hide the form. </p>

<p>The form will display itself when it has a need to (think along the lines of a outlook 2003 style popup), but I can' figure out how to hide the form on load without something messy.</p>

<p>Any suggestions?</p>

[{'answer_id': 70282, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': -1, 'selected': False, 'text': "<p>Here is a simple approach:<br>\nIt's in C# (I don't have VB compiler at the moment)</p>\n\n<pre><code>public Form1()\n{\n    InitializeComponent();\n    Hide(); // Also Visible = false can be used\n}\n\nprivate void Form1_Load(object sender, EventArgs e)\n{\n    Thread.Sleep(10000);\n    Show(); // Or visible = true;\n}\n</code></pre>\n"}, {'answer_id': 70283, 'author': 'deemer', 'author_id': 11192, 'author_profile': 'https://Stackoverflow.com/users/11192', 'pm_score': -1, 'selected': False, 'text': "<p>In the designer, set the form's Visible property to false.  Then avoid calling Show() until you need it.  </p>\n\n<p>A better paradigm is to not create an instance of the form until you need it.</p>\n"}, {'answer_id': 70296, 'author': 'Grokys', 'author_id': 6448, 'author_profile': 'https://Stackoverflow.com/users/6448', 'pm_score': 8, 'selected': True, 'text': "<p>I'm coming at this from C#, but should be very similar in vb.net.</p>\n\n<p>In your main program file, in the Main method, you will have something like:</p>\n\n<pre><code>Application.Run(new MainForm());\n</code></pre>\n\n<p>This creates a new main form and limits the lifetime of the application to the lifetime of the main form.</p>\n\n<p>However, if you remove the parameter to Application.Run(), then the application will be started with no form shown and you will be free to show and hide forms as much as you like.</p>\n\n<p>Rather than hiding the form in the Load method, initialize the form before calling Application.Run(). I'm assuming the form will have a NotifyIcon on it to display an icon in the task bar - this can be displayed even if the form itself is not yet visible. Calling <code>Form.Show()</code> or <code>Form.Hide()</code> from handlers of NotifyIcon events will show and hide the form respectively.</p>\n"}, {'answer_id': 70462, 'author': 'Roger Willcocks', 'author_id': 11511, 'author_profile': 'https://Stackoverflow.com/users/11511', 'pm_score': 0, 'selected': False, 'text': "<p>Launching an app without a form means you're going to have to manage the application startup/shutdown yourself.</p>\n\n<p>Starting the form off invisible is a better option.</p>\n"}, {'answer_id': 189045, 'author': 'Tute', 'author_id': 4386, 'author_profile': 'https://Stackoverflow.com/users/4386', 'pm_score': 5, 'selected': False, 'text': '<p>I use this:</p>\n\n<pre><code>private void MainForm_Load(object sender, EventArgs e)\n{\n    if (Settings.Instance.HideAtStartup)\n    {\n        BeginInvoke(new MethodInvoker(delegate\n        {\n            Hide();\n        }));\n    }\n}\n</code></pre>\n\n<p>Obviously you have to change the if condition with yours.</p>\n'}, {'answer_id': 398051, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This example supports total invisibility as well as only NotifyIcon in the System tray and no clicks and much more.</p>\n\n<p>More here: <a href="http://code.msdn.microsoft.com/TheNotifyIconExample" rel="nofollow noreferrer">http://code.msdn.microsoft.com/TheNotifyIconExample</a></p>\n'}, {'answer_id': 398528, 'author': 'Benjamin Autin', 'author_id': 1440933, 'author_profile': 'https://Stackoverflow.com/users/1440933', 'pm_score': -1, 'selected': False, 'text': "<p>Why do it like that at all?</p>\n\n<p>Why not just start like a console app and show the form when necessary? There's nothing but a few references separating a console app from a forms app.</p>\n\n<p>No need in being greedy and taking the memory needed for the form when you may not even need it.</p>\n"}, {'answer_id': 403898, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Extend your main form with this one:</p>\n\n<pre><code>using System.Windows.Forms;\n\nnamespace HideWindows\n{\n    public class HideForm : Form\n    {\n        public HideForm()\n        {\n            Opacity = 0;\n            ShowInTaskbar = false;\n        }\n\n        public new void Show()\n        {\n            Opacity = 100;\n            ShowInTaskbar = true;\n\n            Show(this);\n        }\n    }\n}\n</code></pre>\n\n<p>For example:</p>\n\n<pre><code>namespace HideWindows\n{\n    public partial class Form1 : HideForm\n    {\n        public Form1()\n        {\n            InitializeComponent();\n        }\n    }\n}\n</code></pre>\n\n<p>More info in this article (spanish):</p>\n\n<p><a href="http://codelogik.net/2008/12/30/primer-form-oculto/" rel="noreferrer">http://codelogik.net/2008/12/30/primer-form-oculto/</a></p>\n'}, {'answer_id': 1173347, 'author': 'Jon Onstott', 'author_id': 132374, 'author_profile': 'https://Stackoverflow.com/users/132374', 'pm_score': -1, 'selected': False, 'text': '<p>Based on various suggestions, all I had to do was this:</p>\n\n<p>To hide the form:</p>\n\n<pre><code>Me.Opacity = 0\nMe.ShowInTaskbar = false\n</code></pre>\n\n<p>To show the form:</p>\n\n<pre><code>Me.Opacity = 100\nMe.ShowInTaskbar = true\n</code></pre>\n'}, {'answer_id': 2447201, 'author': 'kilsek', 'author_id': 293971, 'author_profile': 'https://Stackoverflow.com/users/293971', 'pm_score': 0, 'selected': False, 'text': '<pre><code>static void Main()\n{\n    Application.EnableVisualStyles();\n    Application.SetCompatibleTextRenderingDefault(false);\n    MainUIForm mainUiForm = new MainUIForm();\n    mainUiForm.Visible = false;\n    Application.Run();\n}\n</code></pre>\n'}, {'answer_id': 4210040, 'author': 'Paul Aicher', 'author_id': 511439, 'author_profile': 'https://Stackoverflow.com/users/511439', 'pm_score': 7, 'selected': False, 'text': '<p>Usually you would only be doing this when you are using a tray icon or some other method to display the form later, but it will work nicely even if you never display your main form.</p>\n\n<p>Create a bool in your Form class that is defaulted to false:</p>\n\n<pre><code>private bool allowshowdisplay = false;\n</code></pre>\n\n<p>Then override the SetVisibleCore method</p>\n\n<pre><code>protected override void SetVisibleCore(bool value)\n{            \n    base.SetVisibleCore(allowshowdisplay ? value : allowshowdisplay);\n}\n</code></pre>\n\n<p>Because Application.Run() sets the forms .Visible = true after it loads the form this will intercept that and set it to false.  In the above case, it will always set it to false until you enable it by setting allowshowdisplay to true.</p>\n\n<p>Now that will keep the form from displaying on startup, now you need to re-enable the SetVisibleCore to function properly by setting the allowshowdisplay = true. You will want to do this on whatever user interface function that displays the form.  In my example it is the left click event in my notiyicon object:</p>\n\n<pre><code>private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)\n{\n    if (e.Button == System.Windows.Forms.MouseButtons.Left)\n    {\n        this.allowshowdisplay = true;\n        this.Visible = !this.Visible;                \n    }\n}\n</code></pre>\n'}, {'answer_id': 5342362, 'author': 'Jeff', 'author_id': 556470, 'author_profile': 'https://Stackoverflow.com/users/556470', 'pm_score': 4, 'selected': False, 'text': "<p>At form construction time (Designer, program Main, or Form constructor, depending on your goals),</p>\n\n<pre><code> this.WindowState = FormWindowState.Minimized;\n this.ShowInTaskbar = false;\n</code></pre>\n\n<p>When you need to show the form, presumably on event from your NotifyIcon, reverse as necessary,</p>\n\n<pre><code> if (!this.ShowInTaskbar)\n    this.ShowInTaskbar = true;\n\n if (this.WindowState == FormWindowState.Minimized)\n    this.WindowState = FormWindowState.Normal;\n</code></pre>\n\n<p>Successive show/hide events can more simply use the Form's Visible property or Show/Hide methods.</p>\n"}, {'answer_id': 5516790, 'author': 'Eugenio Miró', 'author_id': 41236, 'author_profile': 'https://Stackoverflow.com/users/41236', 'pm_score': 0, 'selected': False, 'text': '<p>As a complement to <a href="https://stackoverflow.com/questions/70272/single-form-hide-on-startup/70296#70296">Groky\'s response</a> (which is actually the best response by far in my perspective) we could also mention the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.applicationcontext.aspx?appId=Dev10IDEF1&amp;l=EN-US&amp;k=k%28%22SYSTEM.WINDOWS.FORMS.APPLICATIONCONTEXT.#CTOR%22%29;k%28APPLICATIONCONTEXT%29;k%28SOLUTIONITEMSPROJECT%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK&amp;k=VERSION=V4.0%22%29;k%28DevLang-CSHARP%29&amp;rd=true" rel="nofollow noreferrer">ApplicationContext</a> class, which allows also (as it\'s shown in the article\'s sample) the ability to open two (or even more) Forms on application startup, and control the application lifetime with all of them.</p>\n'}, {'answer_id': 11831856, 'author': 'Chriz', 'author_id': 1579761, 'author_profile': 'https://Stackoverflow.com/users/1579761', 'pm_score': 4, 'selected': False, 'text': '<pre><code>    protected override void OnLoad(EventArgs e)\n    {\n        Visible = false; // Hide form window.\n        ShowInTaskbar = false; // Remove from taskbar.\n        Opacity = 0;\n\n        base.OnLoad(e);\n    }\n</code></pre>\n'}, {'answer_id': 13785671, 'author': 'echoen', 'author_id': 1889095, 'author_profile': 'https://Stackoverflow.com/users/1889095', 'pm_score': 2, 'selected': False, 'text': '<p>I have struggled with this issue a lot and the solution is much simpler than i though.\nI first tried all the suggestions here but then i was not satisfied with the result and investigated it a little more.\nI found that if I add the:<br></p>\n\n<pre><code> this.visible=false;\n /* to the InitializeComponent() code just before the */\n this.Load += new System.EventHandler(this.DebugOnOff_Load);\n</code></pre>\n\n<p>It is working just fine.\nbut I wanted a more simple solution and it turn out that if you add the: </p>\n\n<pre><code>this.visible=false;\n/* to the start of the load event, you get a\nsimple perfect working solution :) */ \nprivate void\nDebugOnOff_Load(object sender, EventArgs e)\n{\nthis.Visible = false;\n}\n</code></pre>\n'}, {'answer_id': 17342392, 'author': 'steve_k', 'author_id': 1577871, 'author_profile': 'https://Stackoverflow.com/users/1577871', 'pm_score': -1, 'selected': False, 'text': "<p>I do it like this - from my point of view the easiest way:</p>\n\n<p>set the form's 'StartPosition' to 'Manual', and add this to the form's designer:</p>\n\n<pre><code>Private Sub InitializeComponent()\n.\n.\n.\nMe.Location=New Point(-2000,-2000)\n.\n.\n.\nEnd Sub\n</code></pre>\n\n<p>Make sure that the location is set to something beyond or below the screen's dimensions. Later, when you want to show the form, set the Location to something within the screen's dimensions.</p>\n"}, {'answer_id': 36010671, 'author': 'George', 'author_id': 4365852, 'author_profile': 'https://Stackoverflow.com/users/4365852', 'pm_score': 2, 'selected': False, 'text': "<p>You're going to want to set the window state to minimized, and show in taskbar to false. Then at the end of your forms Load set window state to maximized and show in taskbar to true</p>\n\n<pre><code>    public frmMain()\n    {\n        Program.MainForm = this;\n        InitializeComponent();\n\n        this.WindowState = FormWindowState.Minimized;\n        this.ShowInTaskbar = false;\n    }\n\nprivate void frmMain_Load(object sender, EventArgs e)\n    {\n        //Do heavy things here\n\n        //At the end do this\n        this.WindowState = FormWindowState.Maximized;\n        this.ShowInTaskbar = true;\n    }\n</code></pre>\n"}, {'answer_id': 40298412, 'author': 'Metallic Skeleton', 'author_id': 4002198, 'author_profile': 'https://Stackoverflow.com/users/4002198', 'pm_score': 3, 'selected': False, 'text': '<p>Try to hide the app from the task bar as well.</p>\n\n<p>To do that please use this code.</p>\n\n<pre><code>  protected override void OnLoad(EventArgs e)\n  {\n   Visible = false; // Hide form window.\n   ShowInTaskbar = false; // Remove from taskbar.\n   Opacity = 0;\n\n   base.OnLoad(e);\n   }\n</code></pre>\n\n<p>Thanks.\n Ruhul</p>\n'}, {'answer_id': 42573333, 'author': 'Willy David Jr', 'author_id': 6542896, 'author_profile': 'https://Stackoverflow.com/users/6542896', 'pm_score': 1, 'selected': False, 'text': '<p>This works perfectly for me:</p>\n\n<pre><code>[STAThread]\n    static void Main()\n    {\n        try\n        {\n            frmBase frm = new frmBase();               \n            Application.Run();\n        }\n</code></pre>\n\n<p>When I launch the project, everything was hidden including in the taskbar unless I need to show it..</p>\n'}, {'answer_id': 44384424, 'author': 'LKane', 'author_id': 8118322, 'author_profile': 'https://Stackoverflow.com/users/8118322', 'pm_score': 1, 'selected': False, 'text': '<p>Override OnVisibleChanged in Form</p>\n\n<pre><code>protected override void OnVisibleChanged(EventArgs e)\n{\n    this.Visible = false;\n\n    base.OnVisibleChanged(e);\n}\n</code></pre>\n\n<p>You can add trigger if you may need to show it at some point</p>\n\n<pre><code>public partial class MainForm : Form\n{\npublic bool hideForm = true;\n...\npublic MainForm (bool hideForm)\n    {\n        this.hideForm = hideForm;\n        InitializeComponent();\n    }\n...\nprotected override void OnVisibleChanged(EventArgs e)\n    {\n        if (this.hideForm)\n            this.Visible = false;\n\n        base.OnVisibleChanged(e);\n    }\n...\n}\n</code></pre>\n'}, {'answer_id': 52763389, 'author': 'Plague', 'author_id': 10490551, 'author_profile': 'https://Stackoverflow.com/users/10490551', 'pm_score': 2, 'selected': False, 'text': '<p>Put this in your Program.cs:</p>\n\n<pre><code>FormName FormName = new FormName ();\n\nFormName.ShowInTaskbar = false;\nFormName.Opacity = 0;\nFormName.Show();\nFormName.Hide();\n</code></pre>\n\n<p>Use this when you want to display the form:</p>\n\n<pre><code>var principalForm = Application.OpenForms.OfType&lt;FormName&gt;().Single();\nprincipalForm.ShowInTaskbar = true;\nprincipalForm.Opacity = 100;\nprincipalForm.Show();\n</code></pre>\n'}, {'answer_id': 55231693, 'author': 'blind Skwirl', 'author_id': 5271220, 'author_profile': 'https://Stackoverflow.com/users/5271220', 'pm_score': 0, 'selected': False, 'text': "<p>I had an issue similar to the poster's where the code to hide the form in the form_Load event was firing before the form was completely done loading, making the Hide() method fail (not crashing, just wasn't working as expected).</p>\n\n<p>The other answers are great and work but I've found that in general, the form_Load event often has such issues and what you want to put in there can easily go in the constructor or the form_Shown event. </p>\n\n<p>Anyways, when I moved that same code that checks some things then hides the form when its not needed (a login form when single sign on fails), its worked as expected.</p>\n"}, {'answer_id': 56698263, 'author': 'Muhammad Rashed Nadeem', 'author_id': 1161905, 'author_profile': 'https://Stackoverflow.com/users/1161905', 'pm_score': 0, 'selected': False, 'text': '<pre><code>    static void Main()\n        {\n            Application.EnableVisualStyles();\n            Application.SetCompatibleTextRenderingDefault(false);\n            Form1 form1 = new Form1();\n            form1.Visible = false;\n            Application.Run();\n\n        }\n private void ExitToolStripMenuItem_Click(object sender, EventArgs e)\n        {\n            this.Close();\n            Application.Exit();\n        }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/70272', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1500/']