screen resolution

How do you write delphi code that adapts form size to screen resolution without distorting the layout of the components?
For example: VGA, SVGA or XVGA-sized screens all using the same program.
casalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

casalAuthor Commented:
Comment: I mean mainly for Delphi graphics, but also for adapting the size of memos, buttons, edits, labels etc.
0
casalAuthor Commented:
Comment: I mean mainly for Delphi graphics, but also for adapting the size of memos, buttons, edits, labels etc.
0
MadshiCommented:
Do you have Delphi4?
In Delphi4 you can design the form in a specific size and design the components (by using anchors) in a way that they automatically fill the form when it is resized. It's just like you would set "align:=alClient", but for each and every component and much better.
Then of course you would have to set your window state to "wsMaximized" so that it fills the whole screen.

Does this help?

Regards, Madshi.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

heathprovostCommented:
Madshi is right.  If you dont have Delphi4 though there is a component available called TSizer that does this for Delphi 2 and 3.  It is available from DelphiX or Delphi Super Page but it is not freeware.  The alternative would be to write event code on the resize event to move everything around but this is quit complex.  May be simpler and faster though if there are not alot of components to move and everything is static.  If you want code examples let me know.
0
rwilson032697Commented:
There are several components on DSP that will help you in this sort of sizing - but they don't quite always get it right and some of the behaviours may seem a little strange.

Raymond.
0
ZifNabCommented:
you can receive an event when windows changes it's display settings.. not that much... only converting a C-library to delphi.
0
viktornetCommented:
Here is something that might help....

unit Scaler;

     interface

     uses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
     Dialogs;
     const
        ScreenWidth  : Integer = 800; //If you don't want to declare
constants
                                     //you'd have to have a
        ScreenHeight : Integer = 600;//property for each of these two so
you can
    // declare it at //designtime
     type
       TScaler = class(TComponent)
       private
         FAllScaled : Boolean;
       protected
         { Protected declarations }
       public
         constructor Create(AOwner : TComponent);override;
         procedure Loaded;override;
       published
         { Published declarations }
       end;
     procedure Register;
     implementation
constructor TScaler.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
  fAllScaled := False;
end;
procedure TScaler.Loaded;
begin
  Inherited;
  if not(csDesigning in ComponentState) then
    if Owner is TForm then
    with TForm(Owner) do begin
      Font.Pitch := fpVariable;
      if (not fAllScaled)and((Screen.Width<>ScreenWidth)or(Screen.Height<>ScreenHeight))then
       begin
         Scaled := True;
         AutoScroll := False;
          if Screen.Width < ScreenWidth then
         ScaleBy(Screen.Width, ScreenWidth)
         else ScaleBy(ScreenWidth, Screen.Width);
         fAllScaled := True;
       end;
     end;
end;
procedure Register;
begin
  RegisterComponents('System', [TScaler]);
end;
end.

Scales all the components if in different resolution...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
viktornetCommented:
By the way this is a component that resizes your form and all the components if the screen resolution is different then the one specified by the constants in the top of the source file... YOu can implement options for each of these constants so you can change it at design time... If you want I can do it for you, just say soooooo/.....

-Viktor
--Ivanov
0
xpherCommented:
Hi
This is what i do

var
  Form1: TForm1;

implementation
  const
       ScreenWidth: Integer = 800; //your screensizes
       ScreenHeight: Integer = 600;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
Scaled := True;
  if (Screen.Width <> ScreenWidth) then
  begin
       Height := Height * Screen.Height div ScreenHeight;
       Width := Width * Screen.Width div ScreenWidth;
       ScaleBy(Screen.Width, ScreenWidth)
       end;
end;

Works for me everytime and scales the components too. I also set the Form AutoScroll to False.

I hope this is of some help, and I hope I'm not treading on anyone's toes here.

Happy New Year
Chris

0
viktornetCommented:
Well, that's exactly what my component does!!!
0
viktornetCommented:
It even resizes the FONT depending on the screen resolution...
0
venksCommented:
The viktornet's answer has been tested by me in another question.
Only thing to use true type fonts like Arial(like i do)
and it works fine.Yo do not need anything else.
venks
0
viktornetCommented:
10x venks :)
0
viktornetCommented:
casal, please decide whether you will accept or reject my answer... Thank You!

-Viktor-
0
viktornetCommented:
Thank You!
0
casalAuthor Commented:
I gratefully accept the suggestions of xpher and victornet. Both should get the points I offered. How do I grade them? I do not see a box for grading the contributions.
Casal
0
MadshiCommented:
You could have asked the Customer Service of EE to do that for you - before you accepted the answer. I guess, now it's not possible anymore...
However, you could still the ask the Customer Service about it...
0
viktornetCommented:
casal, yes Madshi is right... you should have customer service to share the points between me and xpher, but since the answer is already accepted you can't do that... ask the customer service and tell them that you made a mistake when accepting an answer...

-Viktor-
0
xpherCommented:
Hi everyone

I'm not bothered about the points. The most important thing is that casal has a successful and understandable answer. After all surely the most important part of these pages is knowledge.

Regards
xpher
0
casalAuthor Commented:
Both VIKTORNET and XPHER gave good answers. Where is the grading box? I'd be willing to give each 200 pints.
Casal.
0
viktornetCommented:
Casal, you already gave all of them to me... you should ask Linda if she can give some to xpher...
0
MadshiCommented:
Hi Casal, if you want to give both Viktor and Xpher 200 points, you should simply ask two new dummy questions. One with the question title "Viktor" with 150 points (you gave him already 50) and one with the title "Xpher" with 200 points.
0
casalAuthor Commented:
Yes, I would like to give Viktor and Xpher and Madshi the points they deserve, but I still don't know how to do it.
Willyou help me please?
Casal.
0
MadshiCommented:
You have already accepted Viktor's answer. If you want to change that, ask in the EE customer forum about that or post new dummy questions in the Delphi forum for us.

Regards, Madshi.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.