Hide form instead of closing when close button clicked

前端 未结 7 1834
南旧
南旧 2020-11-28 08:47

When a user clicks the X button on a form, how can I hide it instead of closing it?

I have tried this.hide() in FormClosing but

7条回答
  •  自闭症患者
    2020-11-28 08:51

    Like so:

    private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason == CloseReason.UserClosing) 
        {
            e.Cancel = true;
            Hide();
        }
    }
    

    (via Tim Huffman)

提交回复
热议问题