title: Adding and removing dynamic controls Windows Forms using C#
body: <p>I have three Tabs in my Windows Forms form. Depending on the selected RadioButton in the <code>TabPages[0]</code>, I added few dynamic controls on the relevant TabPage. On the <code>Button_Click</code> event the controls are added, but the problem is I'm not able to remove the dynamically added controls from the other (irrelevant) TabPage.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>Label label235 = new Label();
  TextBox tbMax = new TextBox();
  label235.Name = "label235";
  tbMax.Name = "txtBoxNoiseMax";
  label235.Text = "Noise";
  tbMax.ReadOnly = true;
  label235.ForeColor = System.Drawing.Color.Blue;
  tbMax.BackColor = System.Drawing.Color.White;
  label235.Size = new Size(74, 13);
  tbMax.Size = new Size(85, 20);
  
  if (radioButton1.Checked)
  {
      label235.Location = new Point(8, 476);
      tbMax.Location = new Point(138, 473);
  
      tabControl.TabPages[1].Controls.Add(label235);
      tabControl.TabPages[1].Controls.Add(tbMax);
  
      tabControl.TabPages[2].Controls.RemoveByKey("label235");
      tabControl.TabPages[2].Controls.RemoveByKey("tbMax");
  }
  else
  {
      label235.Location = new Point(8, 538);
      tbMax.Location = new Point(138, 535);
  
      tabControl.TabPages[1].Controls.RemoveByKey("label235");
      tabControl.TabPages[1].Controls.RemoveByKey("tbMax");
  
      tabControl.TabPages[2].Controls.Add(label235);
      tabControl.TabPages[2].Controls.Add(tbMax);
  }
  </code></pre>
  
  <p>Where am I making that mistake?</p>