question

LooBi avatar image
0 Votes"
LooBi asked LooBi commented

How to expand & reduce panel?

![200710-image.png




I have two panels in tabcontrol.
I want to make panel B reduce when I expand panel A.
and panel A reduce when I expand panel B.
so I mean how to adjust two panels?!
Thank you!

------------Edit------------
I would like to move like this.

200756-ezgifcom-gif-maker.gif



dotnet-csharpwindows-forms
image.png (5.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered LooBi commented

Instead of two panels, insert a SplitContainer control and change its Orientation property to "Horizontal".

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Oh Thank you It works!
Thank you very much.

0 Votes 0 ·
JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered LooBi commented

@LooBi, Welcome to Microsoft Q&A, you could adjuest two panel's size and location to expand or reduce the two panels.

Here is a code example you could refer to.

    Panel panel1 = new Panel();
         Panel panel2 = new Panel();
         private void Form1_Load(object sender, EventArgs e)
         {
              
             panel1.BackColor = Color.Blue;
             panel1.Size=new Size(tabPage1.Width,tabPage1.Height/2);
             panel1.Click += Panel1_Click;
             TextBox textBox1 = new TextBox();
             textBox1.Text = "Hello";
             panel1.Controls.Add(textBox1);
    
             panel2.BackColor = Color.Yellow;
             panel2.Size = new Size(tabPage1.Width, tabPage1.Height / 2);
             panel2.Location = new Point(panel1.Left, panel1.Bottom);
             panel2.Click += Panel2_Click;
             CheckBox checkBox1 = new CheckBox();
             checkBox1.Text = "Do you agree";
             checkBox1.Checked = false;
             panel2.Controls.Add(checkBox1);
             tabPage1.Controls.Add(panel1);
    
             tabPage1.Controls.Add(panel2);
         }
    
         private void Panel2_Click(object sender, EventArgs e)
         {
             panel1.Size = new Size(tabPage1.Width, (tabPage1.Height / 3));
             panel2.Size = new Size(tabPage1.Width, (tabPage1.Height / 3)*2);
             panel2.Location = new Point(panel1.Left, panel1.Bottom);
         }
    
         private void Panel1_Click(object sender, EventArgs e)
         {
             panel1.Size = new Size(tabPage1.Width, (tabPage1.Height / 3) * 2);
             panel2.Size = new Size(tabPage1.Width, (tabPage1.Height / 3));
             panel2.Location = new Point(panel1.Left, panel1.Bottom);
    
         }

Result:

200717-2.gif



As the above picture shown, when I click panel1, panel1 will expand and panel2 will reduce, so on the panel2.

Best Regards,
Jack


If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



2.gif (40.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.