.NET Form
-
Hi all, I've created a user-control, which resides in library of other controls I use in my application. The control has two or three textboxes and some drawn graphics. I've put this control in my main application and it basically works fine. Next I have a class, and I create an instance which stores my data and I serialise this class to file for use later on. The user-control is used to change the values in this object and I do that using an event which is fired when the TextChanged event occurs. What makes it more complicated is I can have multiple instances of the class which I need to switch between and the user-control needs to display the data in the textboxes for the objectI've selected. My problems see to start when I reload my serialized file or switch between the objects. So for example, when I initialise the control I do: usercontrol.textboxA = X.GetParamA; usercontrol.textboxB = X.GetParamB; When I switch between say object X and Y I do usercontrol.textboxA = Y.GetParamA; // This can cause issues as TextChanged is called usercontrol.textboxB = Y.GetParamB; When the user changes a value in the textbox I fire the event which is caught in the form containing the user-control I do: // Get selected object X or Y in this case Y.GetParamA = usercontrol.textboxA; Y.GetParamB = usercontrol.textboxB; This really doesn't feel like the right way to tackle this and I fear my design is off. I though of passing in a reference to my objects or maybe there is a better way to use the events... Any suggestions would be great. Thanks
-
Hi all, I've created a user-control, which resides in library of other controls I use in my application. The control has two or three textboxes and some drawn graphics. I've put this control in my main application and it basically works fine. Next I have a class, and I create an instance which stores my data and I serialise this class to file for use later on. The user-control is used to change the values in this object and I do that using an event which is fired when the TextChanged event occurs. What makes it more complicated is I can have multiple instances of the class which I need to switch between and the user-control needs to display the data in the textboxes for the objectI've selected. My problems see to start when I reload my serialized file or switch between the objects. So for example, when I initialise the control I do: usercontrol.textboxA = X.GetParamA; usercontrol.textboxB = X.GetParamB; When I switch between say object X and Y I do usercontrol.textboxA = Y.GetParamA; // This can cause issues as TextChanged is called usercontrol.textboxB = Y.GetParamB; When the user changes a value in the textbox I fire the event which is caught in the form containing the user-control I do: // Get selected object X or Y in this case Y.GetParamA = usercontrol.textboxA; Y.GetParamB = usercontrol.textboxB; This really doesn't feel like the right way to tackle this and I fear my design is off. I though of passing in a reference to my objects or maybe there is a better way to use the events... Any suggestions would be great. Thanks