Board index » cppbuilder » How to re-size the form according to the screen size

How to re-size the form according to the screen size

Hi All,

I built an application on my PC with 1024 x 768 window size.
What should I do (Add to the forms) so when the application
is run over 800 x 600 windows-size PC, the user get a full screen and doesn't have to scroll Vertical/Horizontal?

Thanks in advance
Rob

 

Re:How to re-size the form according to the screen size


Quote
"Rob Kemp" <Masf140...@yahoo.com> wrote in message

news:3eeb6bfe$1@newsgroups.borland.com...

Quote
> I built an application on my PC with 1024 x 768
> window size. What should I do (Add to the forms)
> so when the application is run over 800 x 600
> windows-size PC, the user get a full screen and
> doesn't have to scroll Vertical/Horizontal?

Better to do it the other way around - design your form for 800x600 and
allow it to stretch larger for 1024x768.  Don't try to design it for
1024x768 and have it shrink for 800x600.  Also, you'll need to make sure the
Align and Anchor properties t make sure things remain positioned where you
want them to be positioned when resizing does occur.

Gambit

Re:How to re-size the form according to the screen size


"Remy Lebeau \(TeamB\)" <gambi...@yahoo.com> wrote:

Quote
> Better to do it the other way around - design your form for
> 800x600 and allow it to stretch larger for 1024x768.

I like that idea. Wish I'd have thought of it.

~ JD

Re:How to re-size the form according to the screen size


Quote
"Rob Kemp" <Masf140...@yahoo.com> wrote:
> What should I do (Add to the forms) so when the application
> is run over 800 x 600 windows-size PC, the user get a full
> screen and doesn't have to scroll Vertical/Horizontal?

The forms on-screen resolution in pixels is a combination of
the forms client and non-client areas. The forms Height and
Width properties only deal with the forms client area so when
you are determining the forms dimensions, you must take into
account that the non-client area is not the same on all
versions of Windows (the height is greater on XP machines).

You can use the global Screen variable to read information
about the desk top height and width and use the win32 API
GetSystemMetrics to read information about the non-client
area. Use this information in the forms constructor to
determine the appropriate values for the forms Height and
Width.

             Screen->DesktopHeight
             Screen->DesktopWidth
             int CaptionHeight = GetSystemMetrics( SM_CYCAPTION );

Note that CaptionHeight + Form1->Height does not equal the on-
screen height in pixels. To get that value, you'll need to do
a few more calls to GetSystemMetrics to get information on
border heights and the main menus height (if you're using one).

In conjunction with resizing the forms dimensions, you'll also
need to reposition the objects on the form. I would approach
this task by dividing the form into specific areas and places
those objects onto panels and use the panels Align properties
so that their Height and Width and Left and Top properties are
automatically adjusted when the forms dimension changes. If
you don't like the visual effect of all the different panels,
change the BorderStyle to bsNone.

For each individual object, use it's Anchors property to
control it's positioning. With luck, you won't need to do any
repositioning of the forms objects.

~ JD

Re:How to re-size the form according to the screen size


But clicking the little square in the top right corner will do this for you.
Alternatively, you can set the window state to wsMaximized.

--
Yours,

Rhys Sage.

Thought of the day:
"Work saves us from three great evils -
vice, boredom and need"

-Voltaire

(Team Zip)

Quote
"Rob Kemp" <Masf140...@yahoo.com> wrote in message

news:3eeb6bfe$1@newsgroups.borland.com...
Quote

> Hi All,

> I built an application on my PC with 1024 x 768 window size.
> What should I do (Add to the forms) so when the application
> is run over 800 x 600 windows-size PC, the user get a full screen and

doesn't have to scroll Vertical/Horizontal?
Quote

> Thanks in advance
> Rob

Re:How to re-size the form according to the screen size


Thanks all for your reply.
I'll re-shape the forms in the 800x600 mode but how can stretch them when the app is run in the 1024x768? how can I detect that?
thanks in advance
Rob

"Remy Lebeau \(TeamB\)" <gambi...@yahoo.com> wrote:

Quote

>"Rob Kemp" <Masf140...@yahoo.com> wrote in message
>news:3eeb6bfe$1@newsgroups.borland.com...

>> I built an application on my PC with 1024 x 768
>> window size. What should I do (Add to the forms)
>> so when the application is run over 800 x 600
>> windows-size PC, the user get a full screen and
>> doesn't have to scroll Vertical/Horizontal?

>Better to do it the other way around - design your form for 800x600 and
>allow it to stretch larger for 1024x768.  Don't try to design it for
>1024x768 and have it shrink for 800x600.  Also, you'll need to make sure the
>Align and Anchor properties t make sure things remain positioned where you
>want them to be positioned when resizing does occur.

>Gambit

Re:How to re-size the form according to the screen size


Simple... Use my resizing library:

//--------------------------------------------------------------------------
-
#include <condefs.h>
#pragma hdrstop
#define Library
#include "ResizeLib.h"
#include <string.h>
// To add a file to the library use the Project menu 'Add to Project'.
void ResizeHandling::RecoverTheMemory(void)
{
delete XTop;
delete XLeft;
delete XHeight;
delete XWidth;

Quote
}

void ResizeHandling::SetMinimumWindowSize(int Vert, int Horiz)
    {
    Horizontal = Horiz;
    Vertical = Vert;
    }

void ResizeHandling::SetVerifiedWindowSize(int& Vert, int& Horiz)
    {
    if(Vert < Vertical) Vert = Vertical;
    if(Horiz < Horizontal) Horiz = Horizontal;
    }

void ResizeHandling::SetWindowSize(int XX, int XY)
{
//Application->MessageBox("You have not paid for this library.", NULL,
MB_OK);
XClientHeight = XX;
XClientWidth = XY;
// now setup TStringLists
XTop = new TStringList();
XLeft = new TStringList();
XHeight = new TStringList();
XWidth = new TStringList();
XComponentIndex = 0;

Quote
}

void ResizeHandling::SetComponent(int XW, int XX, int XY, int XZ)
{
XTop->Add(XW);
XLeft->Add(XX);
XHeight->Add(XY);
XWidth->Add(XZ);

Quote
}

void ResizeHandling::NewWindowSize( int XX, int XY)
{
XNewClientHeight = XX;
XNewClientWidth = XY;

Quote
}

void ResizeHandling::GetComponent(int &XW, int &XX, int &XY, int &XZ)
{
double XTemp;
int XObjectHeight = StrToInt(XHeight->Strings[XComponentIndex]);
int XObjectWidth = StrToInt(XWidth->Strings[XComponentIndex]);
int XObjectTop = StrToInt(XTop->Strings[XComponentIndex]);
int XObjectLeft = StrToInt(XLeft->Strings[XComponentIndex]);
XComponentIndex++;
if(XComponentIndex >= XHeight->Count) XComponentIndex = 0;
// now do calculations
XTemp = XObjectHeight;  // Memo Height
XTemp = XTemp / XClientHeight;  // Screen clientheight
XTemp = XTemp * XNewClientHeight;
XY = XTemp;
// now do width
XTemp = XObjectWidth; // memo width
XTemp = XTemp / XClientWidth; // screen clientwidth
XTemp = XTemp * XNewClientWidth;
XZ = XTemp;
// now do left
XTemp = XObjectLeft; // memo left
XTemp = XTemp / XClientWidth; // screen clientwidth
XTemp = XTemp * XNewClientWidth;
XX = XTemp;
// now do top
XTemp = XObjectTop; // memo top
XTemp = XTemp / XClientHeight; // screen client height
XTemp = XTemp * XNewClientHeight;
XW = XTemp;

Quote
}

#ifndef ResizeLib
#define ResizeLib
#include <Classes.hpp> // String
#include <StdCtrls.hpp>
#include <vcl.h>
class ResizeHandling
{
  public:
  void SetWindowSize(int, int);
  // The format is: ClientHeight, ClientWidth
  void SetComponent(int,int,int,int);
  void NewWindowSize(int,int);
  void GetComponent(int&,int&,int&,int&);
  // note: all components must be set and got in the same order.
  // The format for both set and get is:
  // XTop, Left, XHeight, XWidth.
  void RecoverTheMemory(void);
  private:
TStringList *XTop;
TStringList *XLeft;
TStringList *XHeight;
TStringList *XWidth;
int XComponentIndex;
int XClientHeight;
int XClientWidth;
int XNewClientHeight;
int XNewClientWidth;

Quote
};

#endif

Re:How to re-size the form according to the screen size


Quote
"rob kemp" <Masf140...@yahoo.com> wrote in message

news:3eebbb74@newsgroups.borland.com...

Quote
> I'll re-shape the forms in the 800x600 mode but
> how can stretch them when the app is run in the
> 1024x768? how can I detect that?

You shouldn't need to, if you utilize the Align and Anchor properties,
everything will automatically stretch for you.  If you design a form in
800x600, then it will remain 800x600 even if the monitor is running in
1024x768 mode.  However, you can simply resize the main TForm itself
according to the current global Screen->Width and Screen->Height properties
and everything else should stretch to accondate the new size when Align and
Achors are used.

Gambit

Re:How to re-size the form according to the screen size


Quote
"JD" <nos...@nospam.com> wrote in message

news:3eeb8b31$1@newsgroups.borland.com...

Quote

> The forms on-screen resolution in pixels is a combination of
> the forms client and non-client areas. The forms Height and
> Width properties only deal with the forms client area so when
> you are determining the forms dimensions, you must take into
> account that the non-client area is not the same on all
> versions of Windows (the height is greater on XP machines).

If this is true than what is the difference between Form->Height and
Form->ClientHeight?

Re:How to re-size the form according to the screen size


To add fuel to the fire i can state that at  D3 and i think still
current even after the
report was sent to Borland long ago
  for my self i have placed my own fix in the form.pas file
 in anyways  in the readstate of the form is where the scaling factors
are
caculated via system font info.
  this info is follows the  PPI settings, (large/smal/ fonts);
  anyways the problem is that how borland calculates the values causes
problems
 on Japenese Versions of the OS running an ASCI font set.
 the font size/Height (can't remember which one at the moment) values
report
 unexpect values that can cause a normal app on a system that was
designed at
96 DPI also running in a Japanese system at 96 DPI to shrink your forms
if you
have scale := true;
 this problem does not take place on apps writen in other tools like
VC++ because
of the way its calculated.
  for what ever reason borland does not fully use the PixelsPerInch
value which
 always reports correctly on a Japanese system.
    so i took it onto my self to fix that and also submitted to borland
long ago.
 they replied stated that the problem was varified. then come along
 D4, D5. ...
 problem still exists.
  so there you go.
Quote
DreamChaser wrote:
> "JD" <nos...@nospam.com> wrote in message
> news:3eeb8b31$1@newsgroups.borland.com...

> > The forms on-screen resolution in pixels is a combination of
> > the forms client and non-client areas. The forms Height and
> > Width properties only deal with the forms client area so when
> > you are determining the forms dimensions, you must take into
> > account that the non-client area is not the same on all
> > versions of Windows (the height is greater on XP machines).

> If this is true than what is the difference between Form->Height and
> Form->ClientHeight?

Re:How to re-size the form according to the screen size


Quote
"DreamChaser" <jkof...@bellsouth.net> wrote in message

news:3eebce9a$1@newsgroups.borland.com...

Quote
> If this is true than what is the difference between
> Form->Height and Form->ClientHeight?

JD is mistaken.  The Height is the overall height of the entire window
including the non-client areas, while the ClientHeight is just the client
area only.  I just verified it with an on-screen pixel ruler.

Think about it - if they always had exactly the same value, then there would
be no reason to have two separate properties in the first place.

Gambit

Re:How to re-size the form according to the screen size


Quote
"DreamChaser" <jkof...@bellsouth.net> wrote:

> If this is true...

It is true that the forms on-screen resolution in pixels is a
combination of the forms client and non-client areas. However,
it is NOT true that the forms Height and Width properties only
deal with the forms client area. They do in fact determine the
forms total height in pixels. Good catch thank you. Even
Gambit didn't see it :-0 (or he didn't correct me).

I worked this out a while ago and going back to my code I see
that I incorrectly recalled my methods but the point that I
was trying to get accross was that the non-client area height
can be different - all of which is moot now that I've looked
at my old code. I didn't take advantage of the Align
properties for the panels so I had to manually set their
heights which caused a problem on XP machines. Thus the error
of my ways.

Quote
> than what is the difference between Form->Height and Form->ClientHeight?

I have to admit that I was unaware of the Client properties (I
wonder in what version that they first appeared or if they've
been there all the long). After playing with them a bit I see
that one could use them for what I had suggested but again it's
a big hack instead of just using the Screen->DesktopHeight as
the forms max height and using panels and their Align properties.

~ JD

Re:How to re-size the form according to the screen size


Quote
"JD" <nos...@nospam.com> wrote:
> [...] Even Gambit didn't see it :-0  (or he didn't correct me).

Yes he did. He did it while I was posting a reply to you.

~ JD

Re:How to re-size the form according to the screen size


The VCL also has some methods for scaling controls
    - ScaleBy
    - ScaleControls
    - ChangeScale

e.g.

void __fastcall TForm1::FormCanResize(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{
  if (NewWidth!=Width)
    ScaleControls(NewWidth, Width);

Quote
}

The disadvantage is of course that you can't scale the width and height
independently

Palle

Quote
"Rhys Sage" <No.Spam@ta> wrote in message

news:3eebc51e@newsgroups.borland.com...
Quote
> Simple... Use my resizing library:

Re:How to re-size the form according to the screen size


I wrote that library for use with BCB v3. I don't believe the controls you
mention were introduced before v6.

--
Yours,

Rhys Sage.

Thought of the day:
"Work saves us from three great evils -
vice, boredom and need"

-Voltaire

(Team Zip)

Quote
"Palle Meinert" <i5...@civil.auc.dk> wrote in message

news:3eec6cec$1@newsgroups.borland.com...
Quote
> The VCL also has some methods for scaling controls
>     - ScaleBy
>     - ScaleControls
>     - ChangeScale

> e.g.

> void __fastcall TForm1::FormCanResize(TObject *Sender, int &NewWidth,
>       int &NewHeight, bool &Resize)
> {
>   if (NewWidth!=Width)
>     ScaleControls(NewWidth, Width);
> }

> The disadvantage is of course that you can't scale the width and height
> independently

> Palle

> "Rhys Sage" <No.Spam@ta> wrote in message
> news:3eebc51e@newsgroups.borland.com...
> > Simple... Use my resizing library:

Go to page: [1] [2]

Other Threads