Setting programmatically closereason

后端 未结 4 685
你的背包
你的背包 2021-02-19 10:25

I want to set the CloseReason of a form after I call This.Close() inside the form.

Usually, this forms is closed by itself calling This.Close(), but I want to ask the us

4条回答
  •  独厮守ぢ
    2021-02-19 10:32

    I don't think you can do that, what i always do is to use a flag

    appClosing = true;
    this.Close();
    

    And then check for that:

    protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing && !appClosing)
            {
                if (MessageBox.Show("¿Desea Salir realmente?\nLa factura aun no ha sido pagada por lo que volverá a la pantalla anterior y podrá seguir agregando productos") == DialogResult.No)
                {
                    e.Cancel = true;
                }
            }
            base.OnFormClosing(e);
        }
    

提交回复
热议问题