Form closing immediately after show in C#
I'm having a bit of trouble with a form it's a form designed with the form designer and my project, it closes immediately upon showing. Here's the relevant code:
namespace Grapher
{
    class Program
    {
        static void Main(string[] args)
        {
            InputForm mainForm = new InputForm();
            mainForm.Show();
        }
    }
}
I've开发者_Python百科 tried to put in a for(;;) but that just makes the for hang, I'm probably doing something silly, very new to C#.
Thanks in advance.
Use Application.Run():
namespace Grapher
{
    class Program
    {
        static void Main(string[] args)
        {
            Application.Run(new InputForm());
        }
    }
}
Do:
Application.Run(mainForm);
This will start the UI properly.
You need to call Application.Run(new InputForm()).
Your code simply shows the form, then the program reaches its end (the end of the Main function) and terminates.
Solved this problem using form.ShowDialog() instead of form.Show()
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论