【问题标题】:How do bind a button to an OK Dialog result with winforms [duplicate]如何使用winforms将按钮绑定到OK对话框结果[重复]
【发布时间】:2017-04-13 05:14:25
【问题描述】:

我有一个Form,我已将其作为对话框打开。在Form 我有一个 cancel 和一个 correct 按钮,当用户选择 correct时,我需要从表单中获得积极反馈> 按钮。我将如何将 正确 按钮链接到 OK 对话框结果?

【问题讨论】:

  • 上面写着when not using buttons,但答案涵盖了你的情况。
  • 在表单的属性中,有AcceptButtonCancelButton

标签: c# winforms dialogresult


【解决方案1】:

来自MSDN Button.DialogResult Property的答案是:

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);
}

应用于您的案例,您只需将其分配给您的 正确 按钮的属性:

correct_btn.DialogResult = DialogResult.OK;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    相关资源
    最近更新 更多