Sheenie Sheenie - 1 year ago 72
C# Question

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

I Have a

that I have opened up as a dialog. On the
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
Dialog result?

Answer Source

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.

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

correct_btn.DialogResult = DialogResult.OK;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download