guys!
I’ve got 2 forms in application – working form (frmMain) and form of settings (frmSettings).
There are two buttons on frmSettings – Save and Cancel. In frmMain I use the following approach to show the frmSettings:
private void btnSettings_Click(object sender, EventArgs e)
{
frmSettings = new SettingsForm();
frmSettings.ShowDialog();
// ...
}
The problem is I don’t know, how to detect, which button was pressed on the frmMain – Save or Cancel. The further logic of the program depends on this fact. I need something like this:
private void btnSettings_Click(object sender, EventArgs e)
{
frmSettings = new SettingsForm();
frmSettings.ShowDialog();
if(/* frmSettings.SaveButton.WasClicked == true */)
{
InitializeServices();
}
// ...
}
Please, give me an advice, how to implement such kind of interaction between forms. Better without using global variables for saving buttons state.
Thanks beforehand.
ShowDialog returns a DialogResult object that allow you to know that. You have to:
On Save Button’s click event, set
this.DialogResulttoDialogResult.OKOn Cancel Button’s click event, set
this.DialogResulttoDialogResult.CancelEdited to manage the DialogResult as @tsiorn’s answer: setting form’s DialgoResult insted of setting that property on each button.