Solved

screen resolution

Posted on 1998-12-30
24
625 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:casal
  • 9
  • 5
  • 4
  • +5
24 Comments
 

Author Comment

by:casal
ID: 1353799
Comment: I mean mainly for Delphi graphics, but also for adapting the size of memos, buttons, edits, labels etc.
0
 

Author Comment

by:casal
ID: 1353800
Comment: I mean mainly for Delphi graphics, but also for adapting the size of memos, buttons, edits, labels etc.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353801
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 5

Expert Comment

by:heathprovost
ID: 1353802
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1353803
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353804
you can receive an event when windows changes it's display settings.. not that much... only converting a C-library to delphi.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 500 total points
ID: 1353805
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1353806
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
 
LVL 1

Expert Comment

by:xpher
ID: 1353807
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1353808
Well, that's exactly what my component does!!!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353809
It even resizes the FONT depending on the screen resolution...
0
 
LVL 1

Expert Comment

by:venks
ID: 1353810
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1353811
10x venks :)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353812
casal, please decide whether you will accept or reject my answer... Thank You!

-Viktor-
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353813
Thank You!
0
 

Author Comment

by:casal
ID: 1353814
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1353815
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1353816
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
 
LVL 1

Expert Comment

by:xpher
ID: 1353817
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
 

Author Comment

by:casal
ID: 1353818
Both VIKTORNET and XPHER gave good answers. Where is the grading box? I'd be willing to give each 200 pints.
Casal.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353819
Casal, you already gave all of them to me... you should ask Linda if she can give some to xpher...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353820
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
 

Author Comment

by:casal
ID: 2297162
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
 
LVL 20

Expert Comment

by:Madshi
ID: 2297198
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question