Controls and Properties
-
Hello, I have 11 instances of a control (representing 11 audio channels). This control has, among others, two public boolean properties called SOLO and MUTE. These can be turned on and off by means of two checkboxes, say, chkSolo and chkMute. This is what I need to do: 1) If the user decides to "solo a channel", i.e. set the SOLO property on one of the controls to TRUE, the MUTE property of the other 10 controls should be set. 2) Unchecking the chkSolo box (setting SOLO to FALSE) should "unmute" the other 10 controls. What's the best way of doing this? Should I have a collection of controls? How do I identify which of the controls is being Soloed? Thanks for your help!
-
Hello, I have 11 instances of a control (representing 11 audio channels). This control has, among others, two public boolean properties called SOLO and MUTE. These can be turned on and off by means of two checkboxes, say, chkSolo and chkMute. This is what I need to do: 1) If the user decides to "solo a channel", i.e. set the SOLO property on one of the controls to TRUE, the MUTE property of the other 10 controls should be set. 2) Unchecking the chkSolo box (setting SOLO to FALSE) should "unmute" the other 10 controls. What's the best way of doing this? Should I have a collection of controls? How do I identify which of the controls is being Soloed? Thanks for your help!
I'd say the best way is to create 2 user controls. The first control should contain the channel, the checkboxes Solo and Mute. Let's call it Channel. When chkSolo is clicked, the control should raise an event to notify it. The second control should handle the collection of the first controls. Let's call it Mixer. This control should handle chkSolo click event (preferably a custom event returning your Channel control); Everytime a chkSolo is checked, it needs to save (either the Channel control's index or a reference to the Channel control) which of the channel control is checked, and if it is to be soloed to go through the collection and mute the rest of the controls. If it is to be unchecked the rest of the controls should be unmuted. Therefore, your Mixer will have handled the mute/unmute and you can get the control being soloed (if any) from it. Edbert Sydney, Australia
-
I'd say the best way is to create 2 user controls. The first control should contain the channel, the checkboxes Solo and Mute. Let's call it Channel. When chkSolo is clicked, the control should raise an event to notify it. The second control should handle the collection of the first controls. Let's call it Mixer. This control should handle chkSolo click event (preferably a custom event returning your Channel control); Everytime a chkSolo is checked, it needs to save (either the Channel control's index or a reference to the Channel control) which of the channel control is checked, and if it is to be soloed to go through the collection and mute the rest of the controls. If it is to be unchecked the rest of the controls should be unmuted. Therefore, your Mixer will have handled the mute/unmute and you can get the control being soloed (if any) from it. Edbert Sydney, Australia
Edbert, thanks for your reply! Could you give me an example of what the code for the event and the second control (the collection of controls) should look like? Just an example would be great. Thanks again!
-
Edbert, thanks for your reply! Could you give me an example of what the code for the event and the second control (the collection of controls) should look like? Just an example would be great. Thanks again!
Here's a small example (I'm blind coding, it might have some syntax error): For Channel, you need to raise an event whenever the checkbox is checked:
public event SoloChangedHandler SoloChanged; // Your event
public delegate void SoloChangedHandler(Channel sender); // Your event delegateprivate void OnSoloChanged()
{
if (SoloChanged != null)
SoloChanged(this);
}private void chkSolo_Checked(object sender, EventArgs e)
{
OnSoloChanged(); //Raise your event
}public bool IsSolo
{
get { return chkSolo.Checked; }
set { chkSolo.Checked = value; }
}For Mixer, you need to either keep a reference on the selected Channel, or the index, or both:
private int selectedIndex = -1;
private Channel selectedChannel;private void ctrlSolo_SoloChanged(Channel sender)
{
if (sender.IsSolo)
{
this.selectedIndex = this.Controls.GetChildIndex(sender);
this.selectedChannel = sender;
foreach (Channel channel in this.Controls)
{
if (channel != sender)
{
channel.IsSolo = false; //Or you can move this to the Channel control, set it to false whenever mute is true
channel.IsMute = true;
}
}
}
else
{
this.selectedIndex = -1;
this.selectedChannel = null;
foreach (Channel channel in this.Controls)
{
channel.IsSolo = false;
channel.IsMute = false;
}
}
}That's it. Now you just need to add properties to access the collection of Channels, the SelectedIndex, and the SelectedChannel. Hope that helps! Edbert Sydney, Australia