Windows Forms: User Control Event Handling

16 Views Asked by At

I have a C# Windows form (the "parent") on which is a managed C++ user control ("main UC") which itself contains a managed C++ user control ("child UC"). These are the givens. The child UC is designed to be re-usable so has no knowledge of parent forms etc.

  1. The parent contains a Save button which is set up with the standard event handlers (clicked etc.) to save the form and UC data.
  2. Via a simple event handling system (triggered in the "leave" method), the child UC can signal to the main UC (and hence to the parent form) if any of its elements have been modified, and the parent set a boolean data is modified flag accordingly:
My_Child_UC_Leave(System::Object^ sender, EventArgs^ e)
{
...
<event handler>->Invoke(sender, e);
}
  1. Outside of the child UC, everything works as expected.
  2. But: if I am manipulating the child UC's controls and then click the parent's Save button, the "leave child UC" event fires but nothing else. (If I then click Save again, we are now outside of the child UC, and everything works as expected.)

The application appears to have "lost" the original Save button clicked event. The Sender parameter to the "leave" child UC method does not appear to indicate that the Save button has been pressed.

QUESTIONS

  1. Is event handling the best approach for this type of problem? (If not, alternatives?)
  2. If so, I somehow need to capture the event that caused the child UC to leave (clicking Save in the parent in my example). Any help appreciated! Further details [code etc.] available on request
0

There are 0 best solutions below