방법: 대화 상자의 결과 검색

대화 상자가 닫히면 대화 상자를 표시한 폼이 해당 대화 상자의 DialogResult 속성이나 ShowDialog 메서드에 대한 호출의 반환 값을 참조하여 결과를 검색할 수 있습니다. 그런 다음 이 폼은 반환된 값에 따라 응답합니다.

DialogResult 값을 검색하려면

  • 대화 상자를 표시한 메서드에 다음과 비슷한 코드를 추가합니다.

    일반적으로 이 코드는 대화 상자를 만들고 표시하는 코드 뒤에 배치됩니다.

    Public Sub DisplayDialog()
       ' Create and display an instance of the dialog box.
       Dim dlg as New Form()
    
       ' Show the dialog and determine the state of the 
       ' DialogResult property for the form.
       If dlg.ShowDialog = DialogResult.OK Then
          ' Do something here to handle data from dialog box.
       End If
    End Sub
    
    private void DisplayDialog() 
    {
       // Create and display an instance of the dialog box
       Form dlg = new Form();
    
       // Show the dialog and determine the state of the 
       // DialogResult property for the form.
       if (dlg.ShowDialog() == DialogResult.OK ) 
       {
          // Do something here to handle data from dialog box.
       }
    }
    
    private void DisplayDialog() 
    {
       // Create and display an instance of the dialog box
       Form dlg = new Form();
    
       // Show the dialog and determine the state of the 
       // DialogResult property for the form.
       if (dlg.ShowDialog() == DialogResult.OK ) 
       {
          // Do something here to handle data from dialog box.
       }
    }
    
    private:
       void DisplayDialog()
       {
          // Create and display an instance of the dialog box
          Form^ dlg = gcnew Form();
    
          // Show the dialog and determine the state of the 
          // DialogResult property for the form.
          if (dlg->ShowDialog() == DialogResult::OK )
          {
             // Do something here to handle data from dialog box.
          }
       }
    

    참고

    폼에서 Dispose 메서드를 호출하여 대화 상자를 올바르게 삭제하는 작업은 매우 중요합니다. 닫기 상자를 클릭하거나 Close 메서드를 호출해도 이 작업이 자동으로 수행되지는 않다는 점에 유의하십시오.

참고 항목

작업

방법: 디자인 타임에 대화 상자 만들기

방법: 대화 상자 닫기 및 사용자 입력 유지

개념

대화 상자에 사용자 입력

기타 리소스

Windows Forms 대화 상자

새 Windows Form 만들기