Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Controls and Properties

Controls and Properties

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheBlindWatchmaker
    wrote on last edited by
    #1

    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!

    E 1 Reply Last reply
    0
    • T TheBlindWatchmaker

      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!

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • E Edbert P

        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

        T Offline
        T Offline
        TheBlindWatchmaker
        wrote on last edited by
        #3

        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!

        E 1 Reply Last reply
        0
        • T TheBlindWatchmaker

          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!

          E Offline
          E Offline
          Edbert P
          wrote on last edited by
          #4

          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 delegate

          private 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups