Why do you need Activated
event at all? The FormB.ShowDialog()
opens FormB
in a modal state, so execution of the code in the calling form FormA
is interrupted.
See the sample (to use in the FormA
):
using (FormB frm = new FormB())
if (frm.ShowDialog(this) == DialogResult.OK)
{
// here FormB is closed by user.
}
EDIT
Since FormB
is opened from the MDI parent, you can save the currently active form to variable and then pass the execution to it. Try this in the MDI parent form:
FormA saveForm = ActiveMdiChild as FormA;
using (FormB frm = new FormB())
if (frm.ShowDialog(this) == DialogResult.OK)
{
if (saveForm != null)
saveForm.UpdateDataGridView(); // Call the method of a previously active form.
}
You can also try the ActivateMdiChild
method to activate a child form.