How to set/find/compute the perfect size of a form?

  • Thread starter Thread starter Paul Schwann
  • Start date Start date
P

Paul Schwann

Hi group,

I have a problem with setting the size of a form. Setting some (hard
coded) size in pixels (width/height) works of course. The question I
always had is: How can I determine the perfect size for my form? With
"perfect size" I mean the width and height a form needs to have to
perfectly fit all the components (buttons, labels, text fields etc)
with respect to the margins, paddings and layout constraints WITHOUT
being too big or too small.

Even if start counting the pixels for each component it is a waste of
time because if a different system font a system theme or screen
resolution is used, the size (in pixels) changes.

In Java/AWT, there is function pack() which does exactly this. Is
there an equivalent in C#/.NET/Winforms?

It is also important that this function can be called during runtime.
Some of my forms have a dynamic content based on user selections.
Thus, the "perfect size" needs to be recomputed now and than...

Thanks for any ideas!

Regards,
Paul
 
You should be looking at custom layout engines. Essentially you still need
to look at the sizes and placement of the components but there is a standard
mechanism for accomplishing this.

There are many good examples of custom layout engines on the web. Google for
it.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Hi Bob,

thanks for your answer.
You should be looking at custom layout engines.

Does it mean I have to implement it myself?
Essentially you still need
to look at the sizes and placement of the components but there is a standard
mechanism for accomplishing this.

What is the standard mechanism and where do I find information about
it?
There are many good examples of custom layout engines on the web. Google for
it.

I find it really strange that C#/.NET does not support this out-of-the
box. How do I write GUI applications that work for different kind of
Windows language and screen setups? It seems the Microsoft egineers
did not spend a minute on thinking about this...

Thanks anyway!

Regards,
Paul
 
Back
Top