Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 591367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:37:38+00:00 2026-05-13T15:37:38+00:00

I have a requirement to resize all the controls on a form when my

  • 0

I have a requirement to resize all the controls on a form when my form resizes.
Unfortunately, due to some issues I can not use any container control or make use of anchor/dock property. I need to do everything using code.
I am able to resize the controls as per the ratio the screen is resized. While performing this resizing, I need to calculate the new position of all the controls along with there new size. The issue is while calculating these new points I am getting the new values in decimal and if I round them then it is causing the problems and calculating wrong size and position each time I resize my form.
I saw some third party controls for the same task but they all calculate the position exactly.

Please help me resolve this issue.
Thanks in advance,
Ashish Sharma

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:37:38+00:00Added an answer on May 13, 2026 at 3:37 pm

    Is this C#/Windows Forms?

    Manual scaling is a pain in the neck. Realistically the only way to completely prevent any major rounding errors over the long-term lifetime of a form is to store the original locations and sizes of every control that you reposition/resize, and make all your reposition/resize code relative to the original position as opposed to the current position.

    You’ll end up with some fugliness like this:

    public class Form1
    {
        private Size originalFormSize;
    
        private List<Control> controlsToResize = new List<Control>();
        private List<Point> originalLocations;
        private List<Size> originalSizes;
    
        public Form1()
        {
            InitializeComponent();
            SaveOriginalSizes();
        }
    
        private void SaveOriginalSizes()
        {
            originalFormSize = Size;
            controlsToResize.Add(panel1);
            controlsToResize.Add(panel2);
            ...
            originalLocations = new List<Point>(controlsToResize.Count);
            originalSizes = new List<Size>(controlsToResize.Count);
            foreach (Control c in controlsToResize)
            {
                originalLocations.Add(c.Location);
                originalSizes.Add(c.Size);
            }
        }
    
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            float scaleX = (float)originalFormSize.Width / Size.Width;
            float scaleY = (float)originalFormSize.Height / Size.Height;
            for (int i = 0; i < controlsToResize.Count; i++)
            {
                Control c = controlsToResize[i];
                UpdatePosition(c, originalLocations[i], scaleX, scaleY);
                UpdateSize(c, originalSizes[i], scaleX, scaleY);
            }
        }
    }
    

    …Where obviously you would have to implement the UpdatePosition and UpdateSize methods on your own – I’m assuming you already have some sort of implementation.

    Honestly, it’s pretty god-awful. I would strongly recommend that instead of trying to do any of this, you revisit whatever requirements/design constraints are preventing you from using the Anchor and Dock properties. In all my years, I don’t think I’ve ever heard of a legitimate reason for not using either these or the layout controls TableLayoutPanel/FlowLayoutPanel or both. Those are the way to deal with layouts in WinForms; anything else is a clumsy hack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have requirement to get Facebook friends list with their images. How can I
We have a requirement in project to store all the revisions(Change History) for the
I have requirement to develop DMS(Document Managemen System) with some initial requirements: If possible
I have requirement of specifying web part connections in onet.xml. So when site is
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched
In our project we have requirement that, after receiving sms message from third party
I have a requirement: If I get a file, I am putting the content
I have a requirement to make a large amount of code MISRA compliant. First
We have a requirement to increase the functionality of a grid we are using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.