Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a TableLayoutPanel I need to maximize a panel by double-clicking on it. I mean it to become a one panel control and others get temporarily hidden. In this case, the table layout panel control gets a control which includes only one panel or shows only one panel which fills inside it. Then if the panel which is now maximize will be double-clicked again, the original table of panels appear again. Is there any straightforward way for this purpose? What can I do to manipulate it better?

What I have tried:

Now I manually remove controls from the TableLayoutPanel control and then recreate it after going to restore. But this method has side-effects which I need to avoid.
In the next try, I changed the code to:
private int _columnCount, _rowCount;

private void player_DoubleClicked(object sender, IDisplayable displayable)
{
    if (tableLayout.ColumnCount == 1 && tableLayout.RowCount == 1)
    {
        tableLayout.ColumnCount = _columnCount;
        tableLayout.RowCount = _rowCount;
        foreach (var ctrl in tableLayout.Controls)
        {
            var panel = ctrl as UserControl;
            if (ctrl != sender)
                panel.Visible = true;
        }
    }
    else
    {
        foreach (var ctrl in tableLayout.Controls)
        {
            var panel = ctrl as UserControl;
            if (ctrl != sender)
                panel.Visible = false;
        }
        _columnCount = tableLayout.ColumnCount;
        _rowCount = tableLayout.RowCount;
        tableLayout.RowCount = 1;
        tableLayout.ColumnCount = 1;
    }
}
Posted
Updated 14-Oct-18 21:48pm
v2

1 solution

 
Share this answer
 
Comments
ilostmyid2 14-Oct-18 8:00am    
it doesn't change size of panel which remains shown
Richard MacCutchan 14-Oct-18 8:18am    
Well you need also to add the code to resize it when making it visible.
ilostmyid2 14-Oct-18 8:25am    
i need a way not to change anything regard to visible panels. they get hidden and automatically exposed when i maximize one of them and restore it back.
Richard MacCutchan 14-Oct-18 9:09am    
Yes, using the visible property should achieve that. If you just change the size of a panel inside your window it will affect the size of all the other but not cover them up. You need to move the maximised panel so it covers all the other controls. Then when you close it or make it invisible the others will be shown again.
ilostmyid2 15-Oct-18 3:51am    
I updated the question. Please refer to the code. It works partially. When I double-click the panels in the first row, they get maximized, but when I click on the 2nd row panels, they expand in the second row. I don't know why they don't get maximized in the whole panel!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900