A very common problem with forms is getting the result of a dialog form. Dialogs are used to ask a question or to get a response. If it’s a simple question with a Yes/No or OK answer, then the standard dialog form is quick and easy to create, and simple to use. But if the user must enter some value or select from an option, getting the information from the form requires extra code.
For a Windows Forms application, creating a new form is as easy as Project / Add Windows Form / Windows Form. But what if you need to set this form up with some data that exists in the main form? How do you populate the controls and variables in the new form with the existing values from the main form?
Passing values between forms is one of the trickiest bits of a multi form application for new VB .Net programmers, but that’s partly because there are so many ways to handle it. When a form needs to know where it came from, there is a property of the form that can provide just that information, if it’s set up properly.
Even if you identify the form that opened a subsidiary form, it’s not always easy to update controls on the form with new values. This snippet shows how it is done.
Messaging between forms is the most robust way of passing data back and forth between forms. It allows you to create forms that can be re-used with a minimum of issues about how you connect data on different forms.