2016-11-29 64 views
0

我有一個Form,我打開了一個對話框。在Form我有一個取消和一個正確按鈕,我需要從窗體中獲得正面反饋,當用戶選擇正確按鈕。我將如何去鏈接正確的按鈕到OK對話框結果?如何使用winforms將按鈕綁定到OK對話框的結果

+0

它說'不使用按鍵時'但答案涵蓋你的情況。 – C4u

+0

在表單的屬性上有'AcceptButton'和'CancelButton'。 – active92

回答

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; 
相關問題