0

I have been writing a program with many panels and just today I added a tabControl to help organize things better. I have set the tabControl visibility to false, so the main form is seen first. When buttons are clicked at the top, the respective tab will become visible and the panels will be seen. I'm using buttons because I don't like the look of tabs at the top.

For tab 1, I have placed 17 panels, all on top of each other. While adding them to tab 1, I added them starting with the newest panel (panel 17) to the oldest panel (panel 1). I set panel 1 visibility to true and the remaining panels (2-17) to false. I can see the panels on tab 1, starting with panel 1, clear as day, but when I run the program it is no where to be seen and the other tabs (tabs 2-6) work as expected. Here's my button_click event for tab 1.

 private void btnBusinessPlan_Click(object sender, EventArgs e)
    {
        tabControl1.Visible = true;
        tabPage1.Show();
        tabPage2.SendToBack();
        tabPage3.SendToBack();
        tabPage4.SendToBack();
        tabPage5.SendToBack();
        tabPage6.SendToBack();                                                                                                                      

        panel17.Visible = false;
        panel16.Visible = false;
        panel15.Visible = false;
        panel14.Visible = false;
        panel13.Visible = false;
        panel12.Visible = false;
        panel11.Visible = false;
        panel10.Visible = false;
        panel9.Visible = false;
        panel8.Visible = false;
        panel7.Visible = false;
        panel6.Visible = false;
        panel5.Visible = false;
        panel4.Visible = false;
        panel3.Visible = false;
        panel2.Visible = false; 
        panel1.Visible = true;        
    }

I have even changed the order of the panels, from ascending to descending, in case that worked. Still nothing.

Kayla
  • 165
  • 2
  • 4
  • 13
  • Each panel is placed in different tab page ? From the code it seems that you have only 6 pages, while have 17 panels ? – M_Idrees Sep 12 '15 at 13:52
  • No, all of the 17 panels are in tab 1. They are stacked on top of each other. A _Next_ button is clicked on each panel to go to the next panel. So on panel 1, there is a _Next_ button and when clicked it continues to panel 2. The same repeats on panel 2 through 17. – Kayla Sep 12 '15 at 13:58
  • 3
    "all on top of each other" is the problem. That puts the 2nd panel *inside* the 1st panel. And the 3rd *inside* the 2nd. Etcetera. So if the 1st panel is not visible then none of them are visible. You'll have to fix that with the View > (Other Windows) > Document Outline editor window. Or by using, hehe, [a TabControl](http://stackoverflow.com/a/2798241/17034). – Hans Passant Sep 12 '15 at 13:59
  • Not sure why you want to add so many panels (there are certainly better ways to accomplish whatever you want); but when doing these kind of things is better making sure that the names are descriptive (seems the case here) and then loop through the given controls, in this contained in tabPage1.Controls. That is: `foreach(var Control in tagPage1.Controls) if(Control.Name.Contains("panel")) -> do what you want`. Additionally, the tabPage.SendToBack() doesn't seem required as far as the tabControl takes care of all the ordering; just focus on selecting the tabPage you want. – varocarbas Sep 12 '15 at 13:59
  • When adding so many controls one on top of the other, additionally to making the whole design view very messy, you might have problems as what Hans is highlighting in the comment above: dropping two controls one on top of the other might provoke the first one to become the container of the second one. It is always better to make this kind of control additions at runtime. You might set up a loop and do tabPage1.Controls.Add(curControl), where curControl is a Panel whose name is defined by "panel" + counter. – varocarbas Sep 12 '15 at 14:04
  • A simpler idea: At-least, to keep things simpler, put each separate panel's work in a separate user control. you can create methods / functions in that user control for processing input / output. At-least it will ease you to handle your code. Second lets create a function InitMe() in the form which will initiate all you user controls and when you proceed from one panel to another, you can dynamically add / remove controls to a single panel on the form. – M_Idrees Sep 12 '15 at 14:46

0 Answers0