0

I'm having a strang problem with c# Winforms (not tried VB.NET admittingly) whereby I have a TabControl on a page, and 4 TabPages.

I have some authentication logic to show/hide these TabPages when showing the form after it's been minimised. This "hiding" logic will essentially remove the tabs, and re-insert them when the form authenticates.

So, First the application is minimised. I restore it, fail my authentication and so the tabs are removed. I minimise the application again, restore the window, pass the authentication and the tabs are inserted. However, the controls within the pages that are anchored to opposite sides (so left, right and top, bottom to allow them to stretch) appear to have broken. The top/left positions are ok, but the opposite position appears to have stretched off the visible page!

I'm guessing this is all related to the removal and additions of pages, but has anyone seen this before and know why this happens?? (and more importantly know a work around) :)

Just to note, my code to hide/show the tabs uses a function as follows: -

private void TabControlPageVisible(TabPage page, Boolean show)
    {
        if (show)
        {
            if (!tabControlMain.TabPages.Contains(page))
            {
                tabControlMain.TabPages.Insert(0, page);
                page.ResumeLayout();
            }
        }
        else
        {
            if (tabControlMain.TabPages.Contains(page))
            {
                page.SuspendLayout();
                tabControlMain.TabPages.Remove(page);
            }
        }
    }

Cheers! :)

Max Power
  • 350
  • 4
  • 15

1 Answers1

0

are you using a layout method on each page or you're just positioning the controls? a (troublesome) solution is to store the position of each control. a much better idea would be to use a layout.

darkphoenix
  • 2,147
  • 3
  • 13
  • 14
  • I'm just positioning the controls manually. I've not used layouts within code much, but the way this is behaving it looks like i might have to do something like that if I can't find a solution, and hopefully it'll account for the form size when it comes to redrawing them on! – Max Power Feb 24 '11 at 12:08