Sheenie Sheenie - 6 days ago 6
C# Question

How do bind a button to an OK Dialog result with winforms

I Have a

Form
that I have opened up as a dialog. On the
Form
I have a cancel and a correct button, I need to get the positive feedback from the form when the user selects the correct button. How would I go about linking the correct button to the
OK
Dialog result?

Answer

From MSDN Button.DialogResult Property comes this answer:

private void InitializeMyButton()
{
    // Create and initialize a Button.
    Button button1 = new Button();

    // Set the button to return a value of OK when clicked.
    button1.DialogResult = DialogResult.OK;

    // Add the button to the form.
    Controls.Add(button1);
}

applied to your case you would just simply assign this to the property of your correct button:

correct_btn.DialogResult = DialogResult.OK;