I usually use this template:
TResult result = Generator.AskResult(); class Generator : Form { // set this result appropriately private TResult Result { get; set; } public static TResult AskResult() { var form = new Generator(); form.ShowDialog(); return form.Result; // or fetch a control value directly } }
This makes it work in a single expression, similar to MessageBox, and does not require public access to any controls. You can also include any additional data as parameters for the static method and pass them to the form constructor or set properties accordingly.
Other benefits include the ability, if necessary, to reuse instances of the form.
R. Martinho Fernandes
source share