-1

I am using a panel in my main form to open every other form in my program, I have a menu on the left side that has buttons for every form and sub menus for other stuff, and it works when I have nothing already loaded in the panel but when I do the buttons on the menu sometimes work and sometime don't...

Here are two screenshots of the menu

enter image description here

enter image description here

and this is the code i use to open forms inside the panel

private void abrirHijo(object formHijo)
    {

        panelContenedor.Controls.Clear();            

        Form fh = formHijo as Form;
        fh.TopLevel = false;
        fh.Dock = DockStyle.Fill;
        this.panelContenedor.Controls.Add(fh);
        this.panelContenedor.Tag = fh;
        fh.Show();
    }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
leonidas56
  • 755
  • 1
  • 6
  • 15
  • Try user controllers :https://stackoverflow.com/questions/1379493/what-are-the-purpose-of-user-controls-in-visual-c – Sachith Wickramaarachchi Jun 30 '18 at 18:49
  • It sound like you code is being blocked. Try from menu : Debug : Break All. The see where code is stopped to get a clue what is causing the issue. You may want to look at the call stack : Debug : Windows : Call Stack. – jdweng Jun 30 '18 at 19:52
  • @Sachith changing the whole thing touser controllers is not viable, i have tons of forms already – leonidas56 Jun 30 '18 at 23:06

1 Answers1

0

So i ended up resolving this, so the buttons in the menu in the vertical menu for some reason are added as controls to the panel that i use to put forms in so when i use the "panelContenedor.Controls.Clear();" i end up removing all the buttons, so i ended up doing this and it works

if (panelContenedor.Controls.Count > 6) //it is six because i have 5 controls and when i open a form it turns to six, so if i have a sixth control it means that i have a form open and so i must close it
        {
            panelContenedor.Controls.RemoveAt(6);                                    
        }


        Form fh = formHijo as Form;
        fh.TopLevel = false;
        fh.Dock = DockStyle.Fill;
        this.panelContenedor.Controls.Add(fh);
        this.panelContenedor.Tag = fh;
        fh.Show();
leonidas56
  • 755
  • 1
  • 6
  • 15