Why does ShowDialog always return DialogResult.Cancel?

I have a custom winform dialog. On it I have a shortcut, a text box and two buttons (OK and Cancel). It also declares and defines overloaded execute methods to pass different lists of parameters.

The Winform dialog is invoked as follows:

var theDialog := new InputMsgBox;

if theInputB.Execute('Awesome StackOverflow','Enter Text?',s,var s) = DialogResult.OK then
begin
  Invalidate;
  SetText(s);
end;

The execution of the Winform dialog box is defined as follows:

method InputMsgBox.Execute(Title, theMessage, defaultanswer:string;var thevalue:string): DialogResult;
begin
    result := DialogResult.Cancel;

    Requesttext.Text:=themessage;
    Requesttext.Enabled:=true;
    Requesttext.Visible:=true;
    InputTextBox.Text:=defaultanswer;
    InputTextBox.Enabled:=true;
    InputTextBox.Visible:=true;

    CancelBtn.Enabled:=true;
    CancelBtn.Visible:=true;
    Okbtn.Enabled:=true;
    Okbtn.Visible:=true;

    self.ShowDialog;
    Result := self.DialogResult;
    thevalue:=InputTextBox.Text;
end;

When the execute method returns back to the caller, it always returns DialogResult.Cancel, even when you click OKBtn.

Accordingly, button dialogs are set.

I set AcceptButton and CancelButton in the winform dialog box.

I cannot understand why the showdialog method always returns DialogResult.Cancel.

. - , , , , showdialog = DialogResult.Ok. , , , - , . . ,

+5
2

. Dialog Form Cancel DialogResult. Form_Closing. -, , ShowDialog. , , DialogResult. DialogResult .

Form_Closing, , .

, , , , .

+7

DialogResult - , DialogResult AcceptButton DialogResult.OK.

, .

, DialogResult.Cancel , .

+6

All Articles