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

  • SEARCH
  • Home
  • 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 949289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:22:53+00:00 2026-05-15T23:22:53+00:00

The program I’m working on at the moment uses C# WinForms (on the 2.0

  • 0

The program I’m working on at the moment uses C# WinForms (on the 2.0 .NET Framework, though that probably won’t make a difference in this case). The design calls for the ability to scale a form and all of its controls up and down. I did this by looping through each of the controls, saving their original sizes and locations, and getting their ratio to the original form size to scale with. It looks a little something like this:

const int SCALE_W = 600;
const int SCALE_H = 500;

...

if (!listsBuilt){
    foreach (Control c in this.Controls){
        sizes.Add(c.Size);
        positions.Add(c.Location);
    }
    listsBuilt = true;
}

int count = 0;
foreach (Control c in this.Controls){
    c.Height = this.Height * (sizes[count].Height / SCALE_H);
    c.Width = this.Width * (sizes[count].Width / SCALE_W);
    c.Left = this.Width * (positions[count].X / SCALE_W);
    c.Top = this.Height * (positions[count].Y / SCALE_H);
}

It’s worked great so far, and I’ve been able to make it global and apply it to all my forms. The problem comes when there are hidden objects on the form. I assumed that they would still be instantiated, and when the program first looped through to get the original size/positions of the objects it would pick them up, but that’s not the case. If I switch modes on a form, and show some objects that weren’t there before, then resize it, objects end up in the wrong places with the wrong sizes.

Is there some way for me to force it to instantiate hidden objects at form_load, even if they haven’t been shown yet, so the lists will have the proper values for the proper controls at all times? If I absolutely have to, I could just do a quick loop at the start:

foreach (Control c in this.Controls){
    c.Show();
    c.Hide();
}

but it doesn’t feel like a good way to go about it. It might make the application have an apparent flicker or perceived slowdown to the user. Any suggestions would be welcome (including suggestions relating to the method by which I’m scaling the form, if it’s a particularly bad or inelegant way. I kind of stumbled to my current method with a little guesswork).

Edit: The hidden controls have their visibility set to “False” via the designer. They are shown via the .Show() function at a later point in the program.

Edit Again!: So it turns out that the visibility isn’t even the issue. The issue is rather that as soon as a control is shown, it seems to shuffle around their index in the controls collection, so when I go back and compare to them they’re not in the order that they were when I first filled the comparison List. That means that one control is likely to get compared to the values of another, and end up with that position and size rather than its own.

  • 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-15T23:22:53+00:00Added an answer on May 15, 2026 at 11:22 pm

    Why not use a TableLayoutPanel instead? I think they would do everything you need, with 0 lines of code.

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

Sidebar

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.