C#/.NET - WinForms - Instantiate a Form without showing it

前端 未结 18 1798
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 18:29

I am changing the Visibility of a Form to false during the load event AND the form still shows itself. What is the right event to tie this.Visible = false; to? I\'d like to

18条回答
  •  余生分开走
    2020-12-05 18:41

    I know this is an old question, but I just stumbled upon it and am pretty surprised no one has mentioned SetVisibleCore:

    bool isVisibleCore = false;
    protected override void SetVisibleCore(bool value)
    {
        base.SetVisibleCore(isVisibleCore);
    }
    

    In that code snippet, as long as isVisibleCore remains false, the form will remain invisible. If it's set to false when the form is instantiated, you won't get that brief flash of visibility that you'd get if you set Visible = false in the Shown event.

提交回复
热议问题