Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-07
4
Medium Priority
?
537 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

610 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