I have a winform application that goes with name myForm. Within this form I open another form:
private OtherForm otherForm; //this is a field
private OpenOtherForm()
{
if (otherForm == null)
{
otherForm = new OtherForm();
otherForm.FormClosing += delegate { MessageBox.Show("OtherForm will be closed"); otherForm = null};
}
MessageBox.Show("Form is already active!");
}
This works fine. But I have some methods in the second form as well. I would like to try capturing theire call.
For example if OtherForm.DoSomething() is called within the second form, I want a message box to show thi.
I tried to assign OtherForm.DoSomething() += delegate { /* mesagebox */}; But this does not compile
If you want to respond to a call in another form you could add an event to the other form and raise it in the method you are trying to respond to.