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

前端 未结 18 1767
被撕碎了的回忆
被撕碎了的回忆 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:55

    For a flicker-free Shown solution, also set the form's location off-screen during load:

    private Point startuplocation;
    
    private void Form1_Load(object sender, EventArgs e)
    {
        this.startuplocation = this.Location;
        this.Location = new Point(-1000, -1000);
    }
    
    private void Form1_Shown(object sender, EventArgs e) //fires first time shown
    {
        this.Visible = false;
        this.Location = this.startuplocation;
    }
    

提交回复
热议问题