The reason is that in Windows Forms, the ShowDialog method returns DialogResult . The range of possible values ββdepends on which buttons you have available and their conversion bool? may depend on what they mean in your application. The following is some general logic for handling multiple cases:
public static bool? ShowSettingsDialogFor(ICustomCustomer) { if (cust is BasicCustomer) { DialogResult result = (new BCustomerSettingsDialog()).ShowDialog(); switch (result) { case DialogResult.OK: case DialogResult.Yes: return true; case DialogResult.No: case DialogResult.Abort: return false; case DialogResult.None: case DialogResult.Cancel: return null; default: throw new ApplicationException("Unexpected dialog result.") } } }
source share