Pavel

Pavel

  • 1.6k
  • 170
  • 51.2k

Array of Panels - radiobuttons are invisible

Sep 12 2012 10:10 AM
Hello,

In the Form constructor I generate an array of panels (pnl_ in the code below), that include radiobuttons.
When I visualize the Form, only panels are visible, NOT radiobuttons inside.
Curiously, everything is OK, when I generate only one panel (pnl in the code below).

Where is a problem.

Thanks in advance.

Pavel.

  public partial class Radiobuttons_on_Panel : Form
  {
  private Panel pnl = new Panel();
 private RadioButton rbtn1 = new RadioButton();
  private RadioButton rbtn2 = new RadioButton();

  private Panel[] pnl_ = new Panel[7];
  private RadioButton[] rbtn1_ = new RadioButton[7];
  private RadioButton[] rbtn2_ = new RadioButton[7];

  public Radiobuttons_on_Panel()
  {
  InitializeComponent();

  pnl.Location = new Point(10, 10);
  pnl.Size = new Size(100, 100);
  pnl.BorderStyle = BorderStyle.FixedSingle;

  rbtn1.Location = pnl.Location;
  rbtn1.Text = "AAA";

  rbtn2.Location = new Point(pnl.Location.X, pnl.Location.Y + rbtn1.Height);
  rbtn2.Text = "BBB";

  pnl.Controls.Add(rbtn1);
  pnl.Controls.Add(rbtn2);
  this.Controls.Add(pnl);

  for (int i = 0; i < pnl_.Length; i++)
  {
  pnl_[i] = new Panel();
  pnl_[i].BorderStyle = BorderStyle.FixedSingle;
  pnl_[i].Size = new Size(100, 100);
  pnl_[i].Location = new Point(10 + i * 110, 200);

  rbtn1_[i] = new RadioButton();
  rbtn1_[i].Location = pnl_[i].Location;
  rbtn1_[i].Text = "AAA";

  rbtn2_[i] = new RadioButton();
  rbtn2_[i].Location = new Point(pnl_[i].Location.X, pnl_[i].Location.Y + rbtn1_[i].Height);
  rbtn2_[i].Text = "BBB";

  pnl_[i].Controls.Add(rbtn1_[i]);
  pnl_[i].Controls.Add(rbtn2_[i]);

  this.Controls.Add(pnl_[i]);
  }
  }
  }


Answers (3)