"Dom" <do********@gmail.comwrote:
Sometimes, I have a window nicely laid out, but when it is run on
another PC, the bottom of it is lopped off. I assume this is because
of the resolution. I'm in the habit of adding code in Form_Load, like
this:
this.height = Control.top + control.height + 50
... where Control is what I know is the bottom control. I don't like
doing this, especially when I change the layout and find it doesn't
work anymore. What do others do?
I'll assume you're talking about Windows Forms and not the newer WPF
stuff.
I've rarely seen any problem like that in Windows Forms, because the
layout is pixel-based (unlike traditional Visual Basic, which often
relied on dots per inch and could vary wildly), but I think you might
see this if the other user has changed the settings in Appearance in
Display Properties. For example, they can choose larger fonts in window
title bars, which changes the height as well.
The best solution is probably to make your windows resizable, so that
the user can drag them to whatever size is convenient. Of course, you'll
also need to use docking and margins so that things like status bars
stay at the correct side of the window, and other things expand to fit.
You will find the size-managing containers like SplitPanel and
TableLayoutPanel useful for this.
The more tiresome alternative is to keep counting 50 pixels like you are
doing, but using the proper measurements. You can find some of these as
static properties of the SystemInformation class in the .NET Framework,
e.g. SystemInformation.CaptionHeight for the height of a window title
bar. It's a pain, though, and if you do that, you should also handle
system events so that your window doesn't go crazy if the user changes
the display properties while it is running.
Eq.