What is the best way to hide the main form on application's startup

前端 未结 3 1892
情话喂你
情话喂你 2021-01-25 06:19

What is the best way to hide the main form on application\'s startup to show it later?

If I just call the Hide method in the Load event of this

3条回答
  •  梦毁少年i
    2021-01-25 07:22

    You can proceed like this:

    private void Form1_Load(object sender, EventArgs e)
    {
      if (Settings.Instance.HideAtStartup)
      {
        BeginInvoke(new MethodInvoker(delegate
        {
            Hide();
        }));
    }
    }
    

    An alternative way can be to use the Application.Run(Form) method. You can create the main form with its Visible property initially set to false, and provide no argument to Application.Run() in main loop.

提交回复
热议问题