VB.NET 2008/Visual Basic 2008

대화상자 - 대화 상자의 부모 폼에서 정보 검색과 대화 상자의 결과 검색

본클라쓰 2011. 5. 8. 10:25

대화 상자를 사용하여 수행하려는 작업에 따라 대화 상자의 부모 폼에서 제공하는 정보에 액세스해야 하는 경우가 있다. 이러한 정보는 대화 상자의 초기화에 필요하거나 부모 폼의 응용 프로그램 상태에 대한 특정 세부 사항과 관련된 정보이다.

 

다음 코드는 ParentForm 속성을 사용하여 부모 폼의 속성(Text 속성)에 액세스하는 방법을 보여 준다.

 

Public Sub GetParentText()

    Dim x As String = CType(Me.ParentForm, Form1).Text

End Sub

 

 

 

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

 

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

 

프로그래밍 방식으로 컨트롤이나 폼의 DialogResult 속성을 설정하려면

 

Public Sub InformationProcessed()
    ' This code will set the DialogResult for a form.
    Me.DialogResult = DialogResult.Yes
    ' OR
    ' This code will set the DialogResult for a button.
    Button1.DialogResult = DialogResult.No
End Sub