I’m currently attempting to make a program for a project I’m working on.
I use 2 UserForms that end up embedded into a parent WinForm.
What I need to do, and doesn’t seem to be working, is create a reference to my settings class, and have the user forms directly edit the variable. The data is stored using serialized XML
I have a class that controls the reading/writing of my xml files. It is first created in the ParentForm. I then have several dynamic controls that read from a List<> variable in a seperate user form. I then use that data to create another UserForm which allows me to view/edit those variables.
I can currently view them just fine, but I can’t edit the variables. I’m not very familiar with using references, as most of the time I use either events or just copy data from form to form, causing (what I feel) unnecessary overhead.
To better illustrate
WinForm -> Select Category -> Draw UserForm1 (Show Items in Category) -> Select Item -> Draw UserForm2 (edit items)
All Forms need access to the Settings variable in WinForm.
This is what I’m currently doing:
Edit form:
public partial class EditPage: UserControl
{
public StorageClass refSettings;
public EditPage(ref StorageClass pSettings)
{
refSettings = pSettings;
Categories Form:
public partial class Categories: UserControl
{
public StorageClass programSettings;
public Categories(ref StorageClass pSettings)
{
programSettings = pSettings;
That’s of course not the actual code, but the main thing I’m trying to do.
Any help would be awesome
Edit: I’m not getting any errors. The variable being passed down simply isn’t being updated. When I go to edit it, It simply reverts back after disposing the child editing form.
You could have a common settings class, which reads configuration from the XML, which I belive you already have.
Say you have a drop down selection which indicates which user control to load and display inside
a panel in the MainForm, so you invoke the user control from the SelectionChangedEvent and pass the
settings class to the constructor of the UserControls.
You could also expose events in the UserControls and subscribe to those events from the MainForm
to make any changes in the MainForm, depending on actions in the user controls.
Say you want to edit something fire an event from the usercontrol and subscribe to that event in the MainParent Form and then make changes from the MainForm.