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

I don't know when it was introduced, since I started with BCB5. However, I
know that ScaleBy has at least been there since Delphi 4, since I found
usage of it one of yours old delphi-programs.

That said, I also have developed my own version similar to yours with the
possibility of independent height/width scale and use on only select
controls.

Palle

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

news:3eec7ba7@newsgroups.borland.com...
Quote
> 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)
> "Palle Meinert" <i5...@civil.auc.dk> wrote in message
> news:3eec6cec$1@newsgroups.borland.com...
> > 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:

 

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


One of my old Delphi programs?

The programs on my website were written in either BCB v3 or D3. The BCB v3
stuff uses the resizing library wheras the D3 stuff uses aligned TPanels and
the odd bit of centering coding.

--
Yours,

Rhys Sage.

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

-Voltaire

(Team Zip)

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


"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3eec1a74$1@newsgroups.borland.com...
Quote

> 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.

That was my thought too :)

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


No sorry I have not visited your web-site (but now I might ;-) ), that was a
type-error. I meant one of our old delphi programs.

Palle

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

news:3eec9767@newsgroups.borland.com...
Quote
> One of my old Delphi programs?

> The programs on my website were written in either BCB v3 or D3. The BCB v3
> stuff uses the resizing library wheras the D3 stuff uses aligned TPanels
and
> the odd bit of centering coding.

> --
> Yours,

> Rhys Sage.

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

> -Voltaire

> (Team Zip)

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


Remy,

I changed "Align" to "Client" and added "Height=Screen->Height; Width=Screen->Width;" under "FormCreate"...I couldn't find any real help on An chor nor any example.
Can you please elaborate on how should I do this.
I changed my PC setting to 800x600 to check if the app adjusts itself to the new screen but that didn't work.
please help
thanks
Rob
"Remy Lebeau \(TeamB\)" <gambi...@yahoo.com> wrote:

Quote

>"rob kemp" <Masf140...@yahoo.com> wrote in message
>news:3eebbb74@newsgroups.borland.com...

>> 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


You're welcome :)

sageworld.freeserve.co.uk

--
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:3eecc03c@newsgroups.borland.com...
Quote
> No sorry I have not visited your web-site (but now I might ;-) ), that was
a
> type-error. I meant one of our old delphi programs.

> Palle

> "Rhys Sage" <No.Spam@ta> wrote in message
> news:3eec9767@newsgroups.borland.com...
> > One of my old Delphi programs?

> > The programs on my website were written in either BCB v3 or D3. The BCB
v3
> > stuff uses the resizing library wheras the D3 stuff uses aligned TPanels
> and
> > the odd bit of centering coding.

> > --
> > Yours,

> > Rhys Sage.

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

> > -Voltaire

> > (Team Zip)

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


Remy,

I changed "Align" to "Client" and added "Height=Screen->Height; Width=Screen->Width;" under "FormCreate"...I couldn't find any real help on An chor nor any example.
Can you please elaborate on how should I do this.
I changed my PC setting to 800x600 to check if the app adjusts itself to the new screen but that didn't work.
please help
thanks
Rob
"Remy Lebeau \(TeamB\)" <gambi...@yahoo.com> wrote:

Quote

>"rob kemp" <Masf140...@yahoo.com> wrote in message
>news:3eebbb74@newsgroups.borland.com...

>> 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
"Rob Kemp" <Masf140...@yahoo.com> wrote:
> I changed "Align" to "Client" and added "Height=Screen->Height;
> Width=Screen->Width;" under "FormCreate"

Do not use the OnCreate event. It is a delphi remnent which
can execute before the forms constructor. Use the forms
contructor instead. ie..

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
    // move your OnCreate code to here

Quote
}

Also do not use the OnDestroy event. Use the forms destructor:

//--- Add this to the unit.h -----
        __fastcall TForm1(TComponent* Owner); // duplicate line to show you where to place the next line
        __fastcall TForm1::~TForm1();
//---- Add this to the unit.cpp file ----
__fastcall TForm1::~TForm1()
{
    // Put your OnDestroy code here

Quote
}
> I couldn't find any real help on Anchor nor any example.
> Can you please elaborate on how should I do this.

The Anchor property anchors the control to it's parent. If you
divide the controls on the form into groups and place them on
seperate panels, the panel that they live on will be their
parent and give you better control over their positioning when
the form is resized. The following is from the help file:

   Use Anchors to ensure that a control maintains its current
   position relative to an edge of its parent, even if the
   parent is resized. When its parent is resized, the control
   holds its position relative to the edges to which it is
   anchored.

   If a control is anchored to opposite edges of its parent,
   the control stretches when its parent is resized. For
   example, if a control has its Anchors property set to
   [akLeft, akRight], the control stretches when the width of
   its parent changes.

   Anchors is enforced only when the parent is resized. Thus,
   for example, if a control is anchored to opposite edges of
   a form at design time and the form is created in a
   maximized state, the control is not stretched because the
   form is not resized after the control is created.

   Note: If a control should maintain contact with three edges
   of its parent (hugging one side of the parent and
   stretching the length of that side), use the Align property
   instead. Unlike Anchors, Align allows controls to adjust to
   changes in the size of other aligned sibling controls as
   well as changes to the parents size.

~ JD

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


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

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

Quote
> 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.

That is not what you said earlier.  You originally stated, and I quote:

    "The forms Height and Width properties only deal with the forms client
area ..."

Now you are back-tracking your claims to say something different.  Make up
your mind already :-p

I just posted a screenshot to the .attachments group under the subject "For
JD - Width and Height" which proves that the Height and Width properties are
for the overall height and width of the form, not just the client areas.  I
placed a simple OnResize event handler to the form and outputed its current
Height and Width to the Caption.  When the form is created, and also
manually resized, the Caption displayed the overall values of the form
including the non-client areas.

Gambit

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


Thanks folks for your relies.

However, I still haven't solved my problem yet. I don't know how to change the Anchor property of my main form as I tried
to delete some of the value in the Object Inspector but Borland
doesn't allow that. I put Height=Screen->Height; Width=Screen-

Quote
>Width; under __fastcall TForm1::TForm1(TComponent* Owner)

as suggested by JD and changed the Align to Client.
BUT when I change my monitor resolution to 800x600 to test it, my form still has V and H scroll bars....Am I doing anything wrong?
Didi I miss something?
I thinks my fault was my Form design was done on a 1028x768 resolution screen where you have a "bigger view"
Should I re-do my design in 800x600?
please advise
Thanks you all for your help
Rob
Quote
"JD" <nos...@nospam.com> wrote:

>"Rob Kemp" <Masf140...@yahoo.com> wrote:
>> I changed "Align" to "Client" and added "Height=Screen->Height;
>> Width=Screen->Width;" under "FormCreate"

>Do not use the OnCreate event. It is a delphi remnent which
>can execute before the forms constructor. Use the forms
>contructor instead. ie..

>__fastcall TForm1::TForm1(TComponent* Owner)
>        : TForm(Owner)
>{
>    // move your OnCreate code to here
>}

>Also do not use the OnDestroy event. Use the forms destructor:

>//--- Add this to the unit.h -----
>        __fastcall TForm1(TComponent* Owner); // duplicate line to show you where to place the next line
>        __fastcall TForm1::~TForm1();
>//---- Add this to the unit.cpp file ----
>__fastcall TForm1::~TForm1()
>{
>    // Put your OnDestroy code here
>}

>> I couldn't find any real help on Anchor nor any example.
>> Can you please elaborate on how should I do this.

>The Anchor property anchors the control to it's parent. If you
>divide the controls on the form into groups and place them on
>seperate panels, the panel that they live on will be their
>parent and give you better control over their positioning when
>the form is resized. The following is from the help file:

>   Use Anchors to ensure that a control maintains its current
>   position relative to an edge of its parent, even if the
>   parent is resized. When its parent is resized, the control
>   holds its position relative to the edges to which it is
>   anchored.

>   If a control is anchored to opposite edges of its parent,
>   the control stretches when its parent is resized. For
>   example, if a control has its Anchors property set to
>   [akLeft, akRight], the control stretches when the width of
>   its parent changes.

>   Anchors is enforced only when the parent is resized. Thus,
>   for example, if a control is anchored to opposite edges of
>   a form at design time and the form is created in a
>   maximized state, the control is not stretched because the
>   form is not resized after the control is created.

>   Note: If a control should maintain contact with three edges
>   of its parent (hugging one side of the parent and
>   stretching the length of that side), use the Align property
>   instead. Unlike Anchors, Align allows controls to adjust to
>   changes in the size of other aligned sibling controls as
>   well as changes to the parents size.

>~ JD

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


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

Quote
> Now you are back-tracking your claims to say something
> different.  Make up your mind already :-p

YES I AM !!!

Quote
>> However, it is NOT true that the forms Height and
>> Width properties only deal with the forms client area.

I posted the above in response to Dreamcatcher (I think) who
had asked a question about my first post in the thread which
made me go back to look at the code that was the basis for my
original post.

Not only did I remember things incorrectly (it was one of the
first things I ever did with BCB), once I saw what I was
trying to accomplish in the code, I also realized that the
approach I suggested was WRONG WRONG WRONG.

Quote
> I just posted a screenshot to the .attachments group under
> the subject "For JD - Width and Height"

Without looking at it I know I was wrong. I knew it the moment
I looked at my old code and I'm not too proud to say that I
blew that one completely and it's a tad embarrassing -
especially so considering how simple the solution is (not
considering the implimentation of said solution).

I live for the day when I can bust your chops !!! BEWARE !!!
But I'm not holding my breath ;-)

~ JD

Go to page: [1] [2]

Other Threads