Help with UserControl State Save and Restore
-
Greetings! I'm having a spot of trouble involving the saving and restoring of UserControl states on a form and was wondering if somebody could help me figure it out. Here's some background: 1. I have 11 instances of a UserControl on a form. 2. The UserControl has, among others, two boolean properties "Mute" and "Solo". 3. Everytime the Solo property of a control goes "true", all the OTHER controls are disabled and only the "soloed" control is active. The Mute property of any control other than the soloed control may not be changed while the solo is active. And here's the problem: 1. One or more UserControls may be muted at the time that a particular UserControl is soloed. 2. Upon "unsoloing" the soloed control, the previously muted controls should remain muted. Here's my approach so far and some pseudocode: 1. I have two events - a SoloHandler and a MuteHandler. 2. I'm assuming that the "state memory" code needs to go into the solo handler. 3. Pseudocode
if (sender.Solo) { // save the controls that are currently muted; // execute other code that soloes the control - (already implemented) } else { // restore previous state of controls, and mute controls that were muted prior to soloing }
AND FINALLY... Here's my question to you! How do you suggest I go about saving the state? Should I use an array and store references to the Controls in the collection using the GetChildIndex property? Is there another way that is more elegant and is easier to code? Thanks! -
Greetings! I'm having a spot of trouble involving the saving and restoring of UserControl states on a form and was wondering if somebody could help me figure it out. Here's some background: 1. I have 11 instances of a UserControl on a form. 2. The UserControl has, among others, two boolean properties "Mute" and "Solo". 3. Everytime the Solo property of a control goes "true", all the OTHER controls are disabled and only the "soloed" control is active. The Mute property of any control other than the soloed control may not be changed while the solo is active. And here's the problem: 1. One or more UserControls may be muted at the time that a particular UserControl is soloed. 2. Upon "unsoloing" the soloed control, the previously muted controls should remain muted. Here's my approach so far and some pseudocode: 1. I have two events - a SoloHandler and a MuteHandler. 2. I'm assuming that the "state memory" code needs to go into the solo handler. 3. Pseudocode
if (sender.Solo) { // save the controls that are currently muted; // execute other code that soloes the control - (already implemented) } else { // restore previous state of controls, and mute controls that were muted prior to soloing }
AND FINALLY... Here's my question to you! How do you suggest I go about saving the state? Should I use an array and store references to the Controls in the collection using the GetChildIndex property? Is there another way that is more elegant and is easier to code? Thanks!I hope I got everything! Here is what I would do: //Create an additional boolean Property "BlockMute" in your class "YoureUserControlClass" public bool BlockMute { get { return _blockmute; } set { if(value!=_blockmute) { _blockmute = value; } } } public bool Mute { get { return _mute; } set { if(value!=_mute) { if(Blockmute== false) { _mute = value; } } } } //SoloHandler { YoureUserControlClass actc = sender as YoureUserControlClass; foreach(object o in this.Controls) { if(o is YoureUserControlClass) { YoureUserControlClass c = o as YoureUserControlClass; if(actc.Solo == true) { if(o != sender) { c.Enabled = false; c.Solo = false; c.BlockMute =true; } else { c.Enabled = true; c.BlockMute = false; } } else { c.Enabled = false; c.BlockMute = false; } } } } All the best,:) Martin -- modified at 15:59 Wednesday 28th June, 2006