This is way too simple. Wrap show dialog. Remember, when ShowDialog closes the form, it still exists. Also, don't close it, just hide.
partial class MyDialogForm : Form {
internal MyData ControlsToData() { }
protected override void OnFormClosing(FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.UserClosing) {
e.Cancel = true;
Hide();
}
}
}
MyDialogForm MyDialog = new MyDialogForm();
MyData ShowDialog() {
MyDialog.ShowDialog();
return MyDialog.ControlsToData();
}
MyData ShowDialogWithCancel() {
if (MyDialog.ShowDialog() == DialogResult.Cancel)
return null;
return MyDialog.ControlsToData();
}
—SA