How can a C# UserControl update forms that it opened (i.e., the forms will not be closed and reopened).
Posted on 2011-04-21
I am trying to update forms opened by a UserControl.
I have a UserControl which has two buttons on it, call them button_A and button_B.
* button_A triggers calculations to be made based on inputs on the UserControl.
* button_B triggers three forms to be opened which allow the user to look at the results of the calculations that have been made by the UserControl. These forms are opened using the Show method, not the ShowDialog method.
What I am trying to do is keep the three forms open and updated while the user makes changes to the inputs on the UserControl and pushes button_A to cause new calculations to be made. That is, I want the user to be able to do the following:
1.) Push button_A to perform calculations.
2.) Push button_B to open the three forms that allow the user to look at the results. This is the only time the user will ever push button_B in this scenario.
Loop over the following:
3.1.) Modify the inputs on the UserControl.
3.2.) Push button_A to trigger calcuations to be made.
3.3) Automatically update the three forms that were opened via button_B in step 2. That is, do not push button_B again and do not close and reopen the forms that are already open, just pass them the new results and tell them to present them.
What is a good way to do this?
I considered using something similar to the OwnedForms property of a System.Windows.Forms.Form but a UserControl does not have an OwnedForms. I considered making the UserControl maintain its own list of OwnedForms but the problem is in the maintenance. That is, I don't see an elegant way for the UserControl to find out that a form has
been closed and thus remove it from its list of OwnedForms.
Another option might be for the UserControl to have an 'I have changed' event and for the forms, when created, to 'listen' for that event. If they hear it then they can request new data from their parent UserControl (a pointer to which they keep) and display it. This would avoid the problem of the UserControl having to maintain a list of forms.
I am developing a C# Windows Application with a target framework of .NET 2.0 using Microsoft Visual Studio 2008.
Any help would be appreciated.