Closing a form during a constructor

前端 未结 9 2068
面向向阳花
面向向阳花 2020-12-01 11:59

Is it possible to close a form while the constructor is executing (or simply to stop it showing at this stage)?

I have the following code:

public par         


        
9条回答
  •  日久生厌
    2020-12-01 12:16

    If you want your window to never be seen
    (no flickering windows that open for an instant and then disappear):

    public new void Show()
    {
        if (MyFunc())
            base.Show();
        else
            ; // dispose or whatever
    }
    

    Though Show(...) has 2 overloads and ShowDialog(...) has 2 too.
    Doesn't work for the main form that is opened via Application.Run(). But who would do that anyways? Except there is also a way to open main form without using Application.Run().

提交回复
热议问题