Closing a form immediately after showing in C #

I have problems with the form created in the form with the form designer and my project, it immediately closes when displayed. Here is the relevant code:

namespace Grapher
{
    class Program
    {
        static void Main(string[] args)
        {
            InputForm mainForm = new InputForm();
            mainForm.Show();
        }
    }
}

I tried to insert for (;;), but it just makes it hang, I probably do something stupid, very new for C #.

Thanks in advance.

+3
source share
3 answers

Use Application.Run():

namespace Grapher
{
    class Program
    {
        static void Main(string[] args)
        {
            Application.Run(new InputForm());
        }
    }
}
+11
source

do:

Application.Run(mainForm);

This will launch the user interface.

0
source

You need to call Application.Run(new InputForm()).

Your code simply shows the form, then the program reaches its end (end of function Main) and terminates.

0
source

All Articles