【问题标题】:How to hide Form instead of closing it [duplicate]如何隐藏表单而不是关闭它[重复]
【发布时间】:2013-09-20 16:58:58
【问题描述】:

尝试隐藏表单而不是关闭它,使用

    private void Playlist_FormClosed(object sender, FormClosedEventArgs e)
    {
        if (e.CloseReason == CloseReason.FormOwnerClosing) //if closed by aplication
        {
            this.Close();
        }
        if (e.CloseReason == CloseReason.UserClosing) //if closed by user
        {
            this.Hide();
        }
    }

但它仍然关闭它,如果用户点击关闭

【问题讨论】:

  • 您要捕获的事件是Closed。尝试改为处理Closing,拦截它,取消它,然后隐藏而不是关闭。

标签: c# .net winforms


【解决方案1】:

使用FormClosing 代替FormClosed。在那里你可以做e.Cancel = true; 来实现你所需要的。问题是在FormClosed 事件发生时表单已经关闭,所以Hide() 不会有任何好处,并且您将来将无法使用此对象,如果您尝试使用FormClosed 事件。

【讨论】:

  • 谢谢 - 现在可以了 - 使用 FormClosing - 在关闭过程中而不是 FormClosed - 在关闭过程之后,注意
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-24
  • 1970-01-01
  • 2011-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多