I have windows application form on which i have Lookup (Search Form) which popups as Dialog Form on top of first Form. Through this dialog form's search value I want to see results in form behind. Like when I enter some search text in Dialog Form and click Find Button that Dialog form will close and results will be shown on form behind. Result can be shown in DropDown combo or grid or any control.
But the main thing is to get value from Dialog Fo开发者_StackOverflow中文版rm to Form behind.
One easy way to accomplish this is to have the Find button simply hide the form. Then you can expose the result as a public property of the form and finally the calling routine can close and unload the form when it has gotten the result.
In the calling form...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SelectorDialog As New myDialog
SelectorDialog.ShowDialog()
Dim result As String = SelectorDialog.Result()
SelectorDialog = Nothing
'do something with the result
End Sub
In your dialog form...
Private formResult As String
Public Function Result() As String
Return formResult
End Function
Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
formResult = "some result"
Me.Hide()
End Sub
This is an easy way. You can also wrap the whole thing up in a class as well.
Could you use InputBox
?
This pops up a modal dialog with a textbox and returns the entered string.
You could pass it as a parameter to a subroutine in the other form
精彩评论