Solved

WinForm: Resize a form and 'inner controls' at runtime.

Posted on 2004-10-07
4
527 Views
Last Modified: 2010-08-05
I have user control that contains several panels.
I would like to set the control's (The Form) width and height programmatically at runtime, and have the inside controls resize accordingly... maybe by percentage
Any ideas?
Thanks in advance
0
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:ptmcomp
ID: 12249584
Use the OnLayout event to calculate and set the size of the inner controls.
0
 
LVL 1

Author Comment

by:JElster
ID: 12249784
How? Thanks
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 125 total points
ID: 12262600
That's the code I used in my test project:

The form contained a Panel "pnlHost" which contained four controls.

            private void panel1_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
            {
                  if (e.AffectedControl != null)
                  {
                        Debug.WriteLine(e.AffectedControl.Name);
                  }
                  if (e.AffectedProperty != null)
                  {
                        Debug.WriteLine(e.AffectedProperty.ToString());
                  }
                  if ((e.AffectedControl == pnlHost) && (e.AffectedProperty == "Bounds"))
                  {
                        UpdateInnerControlBounds();
                  }
            }

            private void UpdateInnerControlBounds()
            {
                  pnlHost.Controls[0].Top = 0;
                  pnlHost.Controls[0].Left = 0;
                  pnlHost.Controls[0].Width = 100;
                  pnlHost.Controls[0].Height = (int)(pnlHost.Height * 0.3);

                  pnlHost.Controls[1].Top = 0;
                  pnlHost.Controls[1].Left = 100;
                  pnlHost.Controls[1].Width = pnlHost.Width - 100;
                  pnlHost.Controls[1].Height = pnlHost.Height - 200;

                  pnlHost.Controls[2].Top = pnlHost.Controls[0].Height;
                  pnlHost.Controls[2].Left = 0;
                  pnlHost.Controls[2].Width = 100;
                  pnlHost.Controls[2].Height = pnlHost.Height - pnlHost.Controls[0].Height;

                  pnlHost.Controls[3].Top = pnlHost.Controls[1].Height;
                  pnlHost.Controls[3].Left = 100;
                  pnlHost.Controls[3].Width = pnlHost.Width - 100;
                  pnlHost.Controls[3].Height = 200;      
            }
      }
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question