Override standard close (X) button in a Windows Form

后端 未结 10 1593
独厮守ぢ
独厮守ぢ 2020-12-04 08:43

How do I go about changing what happens when a user clicks the close (red X) button in a Windows Forms application (in C#)?

10条回答
  •  时光说笑
    2020-12-04 08:58

    protected override bool ProcessCmdKey(ref Message msg, Keys dataKey)
        {
            if (dataKey == Keys.Escape)
            {
                this.Close();
                //this.Visible = false;
                //Plus clear values from form, if Visible false.
            }
            return base.ProcessCmdKey(ref msg, dataKey);
        }
    

提交回复
热议问题