Solved

screen resolution

Posted on 1998-12-30
24
621 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
Comment Utility
Comment: I mean mainly for Delphi graphics, but also for adapting the size of memos, buttons, edits, labels etc.
0
 

Author Comment

by:casal
Comment Utility
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
Comment Utility
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
 
LVL 5

Expert Comment

by:heathprovost
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well, that's exactly what my component does!!!
0
 
LVL 10

Expert Comment

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

Expert Comment

by:venks
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
10x venks :)
0
 
LVL 10

Expert Comment

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

-Viktor-
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Thank You!
0
 

Author Comment

by:casal
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now