I have MDI form project and a form called BaseForm which inherits from Form and all the other forms including the MDIparent inherit from this BaseForm. Some of my child forms can be edited so I have Save button. I also ask for save on the parent’s form closing event if there are open editable child forms. I do it like this:
protected void IsEditable()
{
foreach (BaseForm f in MdiChildren)
{
if (f.isEditable == true)
{
MessageBox.Show("To Do Save" + f.GetType().ToString());
f.Close();
}
}
}
The question is that I have already implemented once the save logic for the chilren’s Save button on click event. I don’t want to write the same code again, so is there any way to call the event(that hold the saving logic) from the code above. The check if the form is editable is made in the BaseForm Form.
You can refractor the code in the
SaveButton_Clickto call a Method calledSaveForm(), make this method public, and: