title: How do I control multiple user controls with one button in Windows form?
body: <p>I have a form that will dynamically create user controls, and each of those user controls has a start button and a stop button.  Is there a way to have a start all and stop all button on the form?  </p>
  
  <p>I tried having a Boolean that gets set true when the main form button is clicked, but once the user control is created it does not check the Boolean value.</p>
  
  <p>Here is the code for the main form (vdoPlayer is the user control):</p>
  
  <pre><code>namespace AutoPopulateVideoSaving
  {
      public partial class Form1 : Form
      {
  
          public Form1()
          {
              InitializeComponent();
              DisplayImage();
          }
  
          private void DisplayImage()
          {
              int h = 20;
  
              for (int i = 0; i &lt; 6; i++)
              {
                  int w = i % 2;
                  vdoPlayer np = new vdoPlayer();
  
                  np.Location = new System.Drawing.Point((33 + 408 * w), h);
                  np.Name = "test" + i.ToString();
                  np.Size = new System.Drawing.Size(408, 266);
                  this.Controls.Add(np);
                  h = h + (266 * w);
              }
  
          }
  
          private void StartAllBut_Click(object sender, EventArgs e)
          {
  
          }
  
          private void StopAllBut_Click(object sender, EventArgs e)
          {
  
          }    
      }
  }
  </code></pre>
  
  <p>Here is the code for the user control:</p>
  
  <pre><code>namespace AutoPopulateVideoSaving
  {
      public partial class vdoPlayer : UserControl
      {
  
          public vdoPlayer()
          {
              InitializeComponent();
              VariableClass2.InitiateVariables();
              JPEGStream jpegSource1 = new JPEGStream("http:// IP address /jpg/image.jpg?resolution=320x240");
              jpegSource1.Login = username;
              jpegSource1.Password = password;
              jpegSource1.NewFrame += new NewFrameEventHandler(jpegSource1_NewFrame);
              jpegSource1.VideoSourceError += new VideoSourceErrorEventHandler(jpegSource1_VideoSourceError);
              Player1.VideoSource = jpegSource1;
          }
  
          void jpegSource1_NewFrame(object sender, NewFrameEventArgs eventArgs)
          {
              Bitmap image = new Bitmap(eventArgs.Frame, 320, 240);
              image.Save(someFile, System.Drawing.Imaging.ImageFormat.Bmp);
          }
  
          void jpegSource1_VideoSourceError(object sender, VideoSourceErrorEventArgs eventArgs)
          {
              //Error handler
              Debug.WriteLine(eventArgs.Description);
          }
  
          private void StartBut_Click(object sender, EventArgs e)
          {
              Player1.VideoSource.Start();
          }
  
          private void StopBut_Click(object sender, EventArgs e)
          {
              Player1.VideoSource.Stop();
          }    
      }
  }
  </code></pre>
  
  <p>I don't know what to put in Form1's button click events to control the rest.  Like I said before, I tried using a Boolean, but it didn't work.  Is this even possible?  </p>