formB has a button that is identified on the form as the cancel button.
Is there a way in formA to know when the formB.cancel button was clicked?
Or should I set my own boolean flag?
Can-Ann Wednesday, April 02, 2008 6:19 PM
Can-Ann wrote:
I have two forms:
formA and formB. formA shows formB
formB has a button that is identified on the form as the cancel button.
Is there a way in formA to know when the formB.cancel button was clicked?
Or should I set my own boolean flag?
If FormA is an MdiParent, then you cannot use ShowDialog(). The above suggestions may run into problems with a child form andits parent.
Add this to the child form.
Code Snippet
// Declare a custom delegate for custom custom events.
internal delegate void Form2Event(object sender, EventArgs e);
// Give this event a name that reflects what occurs.
internal event Form2Event CloseButtonClickedEvent;
protected
override void OnClosing(CancelEventArgs e)
{
e.Cancel =
true; // set to false to allow form to close.
base.OnClosing(e);
CloseButtonClickedEvent.Invoke(
this, e);
}
Try this when you load the child form inside of a button click event method.
Code Snippet
Form2
form2 = new Form2();
form2.MdiParent =
this;
form2.Show();
form2.CloseButtonClickedEvent +=
new Form2.Form2Event(form2_CloseButtonClickedEvent);
formB has a button that is identified on the form as the cancel button.
Is there a way in formA to know when the formB.cancel button was clicked?
Or should I set my own boolean flag?
If FormA is an MdiParent, then you cannot use ShowDialog(). The above suggestions may run into problems with a child form andits parent.
Add this to the child form.
Code Snippet
// Declare a custom delegate for custom custom events.
internal delegate void Form2Event(object sender, EventArgs e);
// Give this event a name that reflects what occurs.
internal event Form2Event CloseButtonClickedEvent;
protected
override void OnClosing(CancelEventArgs e)
{
e.Cancel =
true; // set to false to allow form to close.
base.OnClosing(e);
CloseButtonClickedEvent.Invoke(
this, e);
}
Try this when you load the child form inside of a button click event method.
Code Snippet
Form2
form2 = new Form2();
form2.MdiParent =
this;
form2.Show();
form2.CloseButtonClickedEvent +=
new Form2.Form2Event(form2_CloseButtonClickedEvent);