Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[C#] Auto controls resizer

Hi. When i first started coding, i had trouble with make an auto-resizer for the forums. But now, since i have 6 years of experience, it was hella easy to make, so im releasing it! :)
 
(Dont forget to vouch  🤝  )
The good stuff:
This goes under SizeChanged:
Code
           int nextH = (this.Height - current.Height);
           int nextW = (this.Width - current.Width);
           foreach(Control c in controls.Keys)
           {
               if (controls[c]) // If you want the height to be resized also (Very nifty)
               {
                   c.Height += nextH;
               }
               c.Width += nextW;
           }
           current = this.Size;
           this.Text = string.Format("YourForm ({0}, {1})", this.Width, this.Height); //display the width and height (Not needed, just nifty for working on minimumsize)
Declare this in global form:
Code
       Size current = new Size();
       Dictionary<Control, bool> controls = new Dictionary<Control, bool>();
How to use:
Put this in Form_Load:
Code
           current = this.Size;
           controls.Add(this.YourControlWithHeightResize, true);
           controls.Add(this.YourControlNoHeightResize, false);
Enjoy!   👍   - Anon Scripter
What's wrong with using the Anchor property? 6 years and you haven't discovered that yet? 🤨

Code
Size current = new Size();
"current" is actually probably not the best name either since it indicates the Size of the control before the size changed, which definitely implies past-tense.

I also don't see why you're using a Dictionary like this. It doesn't do anything more than a simple collection would because you're still looping through everything anyways by iterating the keys, and doing a lookup from there, rather than just looping through all of the KeyValuePair<TKey, TValue> entities. As long as the hashcode is unique the only thing it does is prevent the same control from being added.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
by AnonynukSep 28, 2026 10:32 AM 2 35 Sep 28, 2026 10:32 AM
Last Post: Anonynuk
[.NET] by ExproMar 25, 2022 03:58 AM 8 722 Mar 25, 2022 03:58 AM
Last Post: SaketSaket
[.NET] by NaywynJun 7, 2020 12:33 AM 32 3,006 Jun 7, 2020 12:33 AM
Last Post: savaganka