Manish Jain

Manish Jain

  • 1.3k
  • 414
  • 9.4k

How can i set panel control inside

Jun 19 2015 8:04 AM


I have a

tablelayoutpanel

in which there are three rows added in designview.
First row contains a panel with maroon color and second and third row contains buttons button_2 and button_3 respectively. There is a button taken outside of this tablelayoutpanel with name button_1.

When user click on this button i am getting its click event and creating two panels with white and blue color resp. inside first row.

private void button1_Click(object sender, EventArgs e)
{
this.tableLayoutPanel1.AutoSize = true;
tableLayoutPanel1.ColumnCount = 2;
tableLayoutPanel1.RowStyles.Insert(1, new RowStyle(SizeType.Percent,100));
tableLayoutPanel1.ColumnStyles.Insert(1, new ColumnStyle(SizeType.Percent, 100));
this.panel1.AutoSize = true;
Panel newPanel = new Panel();
newPanel.BackColor = Color.White;
newPanel.Dock = DockStyle.Fill;
newPanel.AutoSize = true;
tableLayoutPanel1.Controls.Add(newPanel, 0, 1);
Panel newPanel2 = new Panel();
newPanel2.BackColor = Color.Blue;
newPanel2.Dock = DockStyle.Fill;
tableLayoutPanel1.Controls.Add(newPanel2, 1, 0);
tableLayoutPanel1.SetColumnSpan(this.button2, 2);
tableLayoutPanel1.SetColumnSpan(this.button3, 2);
}
 

NEED:

Now i am not able to create next panel in the remaining portion of that row with suppose of black color.

One more thing if there is another button outside of this tablelayoutpanel , then how can i turn back to the previous one after this button click's as that was before creating dynamic panels? I mean first row should contain only one panel that was of maroon color with dock fill.