views:

278

answers:

2

On my notebook with a screen resolution of 1280x800 I've developed an application. Now I want to use it on a desktop computer with a resolution of 1600x1200.

Of course, it's too small on the desktop computer. I've set the sizes so that I could see the whole form on my notebook. But on the desktop computer, everything should be resized.

But on the large screen, things shouldn't be viewed bigger which means that the same amount of information can be displayed. Things should get a higher height and width value so that more information can be displayed.

In complicated code I mean something like this which should run automatically once when the form is created (OnCreate):

devResolutionX := 1280;
devResolutionY := 800;
useResolutionX := 1600; // how to get / read out this property?
useResolutionY := 1200; // how to get / read out this property?
Form1.Height := Form1.Height+devResolutionY-useResolutionY;
Form1.Height := Form1.Width+devResolutionX-useResolutionX;
// do that with all components which makes this approach complicated

What must I work with to reach that goal?

  • ScaleBy
  • alignments
  • anchors

Thank you very much in advance!

+1  A: 

Just set your anchors correctly and the additional info will show. I wouldn't recommend programmatically forcing an arbitrary height and width. The best thing to do is use the form's OnClose event to save the form's height and width and then set the height and width with OnCreate.

David
Thanks, with correct anchors it works fine. And saving the height and width values in OnClose is a good idea, too.
+2  A: 

It looks like you just need to set the BorderStyle property of your form to bsSizeable. This will allow the user to resize the form (or maximize it) as he sees fit.

You will also want to make use of anchors here. If you set the akLeft, akTop, akRight, and akBottom anchors for all the components on your form, they will resize with the form.

As soon as you do this, though, you will probably quickly realize that wasn't actually what you wanted to do after all. These growing components are probably going to overlap with each other. So, you are going to need to put some thought into which edges of which components get anchored and which don't.

Sometimes you will need to do some more complicated component moving and sizing than can be handled by anchors alone. In these cases, you will want to handle the Form's OnResize event. This event will get fired whenever the user resizes the form, and it will give you the chance to do some math to recalulate the sizes and positions of certain components.

Jeff Wilhite
Thank you very much! This is exactly what I've done now. It worked quite good with the anchors but some components were moving and resizing more than others. So I use OnResize additionally.