Question

in the following code I want to get the dialog result of a Form but it's not saved to my variable... why?

My code:

public void xyz() {
    var dialogResult = new DialogResult();
    if (booleanVariable) {
        var form1 = new Form1();
        form1.ShowDialog();
        dialogResult = form1.DialogResult;
    }
    else {
        var form2 = new Form2();
        form2.ShowDialog();
        dialogResult = form2.DialogResult;
    }

    if (dialogResult == DialogResult.OK) {
        ...
    }
}

At the and of my Form1 and Form2 i set the this.DialogResult = DialogResult.OK. At the end of the process my variable dialogResult is DialogResult.None, why?

Était-ce utile?

La solution

public void xyz() {
    var dialogResult = booleanVariable ? new Form1().ShowDialog() : new Form2().ShowDialog();

    if (dialogResult == DialogResult.OK) {
        ...
    }
}

Autres conseils

try to modify this with your IF Statement:

DialogResult var;
Form2 qwerty  = new Form2();
var = qwerty.ShowDialog();
MessageBox.Show(var.ToString());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top