How can I hide form1 while Application.Run(form1) is executing?

how to run second form in c# windows application
c# hide main form
c# hide form
c# open new form and close current
how to close form in c# windows application
c# show form c#
show form 2 c#

I have a form1 that I run with Application.Run.

I want to hide this form (I need it hidden because I run some things in the background, so they must execute) and open another form for a log-in.

The way I am trying this is by executing in my form1 constructor the command this.Hide(); and if log in is successful, show my form1, but it doesn't seem to work. Any ideas?

Just override the OnVisibleChanged method and change the visibility of the form in there, something like this:

protected override void OnVisibleChanged(EventArgs e)
    this.Visible = false;

And that's it! Simple and clean.

How hide Form1 and show Form2? - MSDN, I want to run Form2 and then hide Form1,. when Form2 (If it is the main form, you might need a solution that keeps the application running. Like @darkmage has done, you have to create a new instance of the second form within your main form before you can do anything with it. Then you just hide your main form and show the second one. You can also use the .Show() method if you don't want the form to show dialog style. – ryanulit Dec 23 '09 at 13:21

You can override SetVisibleCore in your Form1 class, to have the Form1 instance hidden on startup. So here is an example which will hide and keep the form hidden, of course you should add some logic that will decide when the form should actually be allowed to become visible.

public partial class Form1 : Form 
  public Form1() 

  protected override void SetVisibleCore(bool value) 
    // Quick and dirty to keep the main window invisible
    // you can put some logic here to decide when to use the
    // incomming value and when to force it to be false as I 
    // am showing here.       

Here is a simple example albeit contrived. Form1 starts invisible and shows Form2, when Form2 is closed it allows Form1 to become visible and shows the form.

using System;
using System.Windows.Forms;

namespace HideMainWinForm
  public partial class Form1 : Form
    // Initially the main form cannot show
    private bool _canShow = false; 

    public Form1()

      Form2 frm = new Form2();
      frm.FormClosed += new FormClosedEventHandler(frm_FormClosed);

    void frm_FormClosed(object sender, FormClosedEventArgs e)
      // Once Form2 is closed we now allow the main form to
      // become visible.
      _canShow = true;

    protected override void SetVisibleCore(bool value)
      base.SetVisibleCore(_canShow && value);

Application.Run Method (System.Windows.Forms), Begins running a standard application message loop on the current thread. Run(context) method, to display multiple forms when the application starts. The class Run(new Form1()); } private void button1_Click(object sender, System. i don't know what code to give you . it's a standard Application.Run(form) executed in Program.cs and in form's constructor there is a this.Hide() – Alex Dec 4 '10 at 12:39 are you executing your background stuff in form1's constructor itself (maybe before calling this.Hide()?) – gideon Dec 4 '10 at 12:55

See this : Use the ApplicationContext Class to Fully Encapsulate Splash Screen Functionality

Its basically talks about how you would show a splash form first, then when you've finished loading, how to call your main form. (If you hide the main form while doing something in the background, do consider a splash screen)

Quote from Introduction: This isn't an example on how to create a splash screen for your app. This article explains a clean way to encapsulate splash screen functionality into an inherited ApplicationContext class. This article also shows in detail what happens behind the scenes when a WinForm app starts.

How to Close LoginForm & Show Main Form in C# without Hiding , When forms close reduce it's form count - when 0, call ExitThread(); . In program.​cs, instaead of calling Application. When that line of code runs, it will wait until that form has closed to run the next line of code. if we use form1.close(),then this application will exit from memory.but form2 will dispear too. Form1 is the default title in a Windows Forms application (Windows Forms is a toolkit for making Windows applications). If you're seeing it, it means someone made a program and didn't retitle the window while making it. Without more information, I can't tell you what it's doing.

If you need to do some background work before you show your form, I would suggest two possible options.

The first one, is to simply do your background work before you create the form and call Application.Run on it.

The second option, if you need a message loop to be active while you do the background work, is to use the Application.Run overload that doesn't take a From as a parameter, and later show your Form exactly when you want to. The only catch is that you will have to cal Application.Exit or Application.ExitThread manually when you want to end the application (because it won't have a Form whose Close event it can watch).

So your code could look something like this:

void Main()
    // trigger some background work

    // and start the message pump

void SomeBackgroundWork()
    // let's say now you completed the background work and you want to show your main Form
    MyForm f = new MyForm();
    f.Close += delegate { Application.Exit(); };

Please comment if some clarification is needed...

[Solved] Open a new form and close the current, without hiding and , Hiding the TextBox on start of the application textBox1.Hide(); 7. Click the Close Double click the Button control that appears in the Form1 form to display the Code When the button is clicked the text of the button changes and a read-only Running the SampleWinApp Windows Application We can also click the Start  To hide a form it is necessary to call the Hide() method of the form to be hidden. Using our example, we will wire up the button on the subForm to close the form. Click on the tab for the second form (the subForm) in your design and double click on the button control to display the Click event procedure.

The problem is the following:

by calling this.Hide() in the constructor you actually set this.Visible = false, but immediately after the form instantiation, form.Show is called (by Application.Run) and form.Show internally set this.Visible = true (well, of course is the opposite of Hide...).

You could do in this way:

private bool firstShow = true;

protected override void OnShown(EventArgs e)
    if (firstShow)
        firstShow = false;

The form will appear for a moment, and then will disappear immediately.

The boolean flag firstShow allows you to hide the form only for the first call of Show() while for the following invocations it will work as usual.

PROGRAMMING IN C#, 3E, When developing a Windows application using C# it is a fairly safe bet to assume that it will consist of In this chapter we will cover the topic of hiding and showing forms when developing applications in C#. Close the running application. Application.Run(New Form1()) End Sub Private Sub button1_Click(sender As object, e As System.EventArgs) ' Populates a list box with three numbers. Dim i As Integer = 3 Dim j As Integer For j = 1 To i - 1 listBox1.Items.Add(j) Next ' Checks to see whether the user wants to exit the application.

Hiding and Showing Forms in C Sharp, (Cefalik) £otalizatie : False location q, Q Some windows hidden while application is running Application running in the foreground You can close the application  Open Form1 after hiding it. I'm new to csharp. Have been coding in VB for a years now, but simple things like form.hide() and then () don't work the same as in VB.

Visual Basic 2005 Made Simple, For example, to refer to the Caption property of Form 1: Form 1. Text = "This is new text" Hiding and showing forms The application we have looked at only If this is the case the form will automatically be displayed when the application runs​. on starting the application, you can specify a module which is executed first. How to: Run an Operation in the Background. 03/30/2017; 6 minutes to read +9; In this article. If you have an operation that will take a long time to complete, and you do not want to cause delays in your user interface, you can use the BackgroundWorker class to run the operation on another thread.

Essential Visual Basic 5.0 Fast: Includes ActiveX Control Development, <summary> /// The main entry point for the application. As a result, they are now displayed on Form1 objects when we execute the program as shown in Figure 13.10. By default this window remains hidden on the left-hand side of the 

  • this.Hide() work for me, we need a code sample reproducing the problem...
  • i don't know what code to give you . it's a standard Application.Run(form) executed in Program.cs and in form's constructor there is a this.Hide()
  • are you executing your background stuff in form1's constructor itself (maybe before calling this.Hide()?)
  • i am executing my background stuff in another thread that sends to my form1 data .
  • possible duplicate of C# Hide new Form at start
  • I am using this right now, and it work perfect, but I cant find the running app if i want to open it? I see its running in task manager when I use you're method. but cant find where it is running tho..
  • @Badescu Alexandru, what is it that does not work? Does the form no hide? Can you share how you tried this?
  • public Form1(){ InitializeComponent(); SetVisibleCore(false); logIn li = new logIn(this); li.Show(); }
  • i've used your function except that instead of "false" at base.SetVisibleCore(false) i've included the bool "value"
  • @Badescu Alexandru, you should not be calling SetVisibleCore, the Framework will call it. You only provide the visiblity logic in the function. See my simplistic updated example.
  • If you use the code in the second example in a new test application, does that do what you expect?
  • The thing is that i am sending data to my form from a thread so i can never exit it , so the first option goes out of order (because there is a stream that is continuous so my program recieves data very often and the second option isn't a valid one because i will require the form to go multiple times to "hidden mode" because a user can log on and off as many times as he want .. and closing the app and restarting it isn't an option