I've read a few articles about disabling Alt+F4 and so far, have got it part functioning.
Currently, I have this on my main form, and it does a great job of only allowing the form to be closed when I need it to..
private void Alerter_FormClosing(object sender, FormClosingEventArgs e)
{
if (_altF4Pressed)
{
if (e.CloseReason == CloseReason.UserClosing)
e.Cancel = true;
_altF4Pressed = false;
}
}
private void Alerter_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt && e.KeyCode == Keys.F4)
_altF4Pressed = true;
}
The problem however, is that this does not work when I display a dialog. The form still closed on Alt+F4, and it's imperative that this does not happen as gives the user a way to circumvent process and procedure.
Currently, my alert form is called using;
public static DialogResult show(string param)
{
thisParam = param;
using (Alerter alert = new Alerter())
{
if (alert.ShowDialog() == DialogResult.OK) { return DialogResult.OK; }
else { return DialogResult.Cancel; }
}
}
and my main form calls it using this;
Alerter.show(rxLine);
How can I prevent the new form from being closed at all, unless I specifically tell it to?