Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Resolution independent applications Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
17-Aug-03
Category
Others
Language
Delphi 2.x
Views
138
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jorge Abel Ayala Marentes

Have you ever wondered how to display your forms and components always the same 
size no matter what the screen resolution is?

Answer:

You have to modify your projectīs DPR file to acomplish that: 
1   
2   // Modify your projects code to achieve resolution independent
3   // applications. I have found that this trick only works for
4   // resolutions greater than the resolution you design the forms, for
5   // example if you design at 800x600 you can use your application at
6   // a resolution of 1024 x 768 or greater.
7   // However it wonīt run fine at 640x480 (altough, nowadays I donīt
8   // kwonw many people with thatv resolution, so I think 800X600 is
9   // fine)
10  
11  program TestResolution;
12  
13  uses
14    Forms,
15    Dialogs,
16    Classes,
17    TypInfo,
18    Windows,
19    Unit1 in 'Unit1.pas' {Form1},
20    Unit2 in 'Unit2.pas' {Form2};
21  
22  {$R *.RES}
23  
24  const
25    //If form is designed in 800 x 600 mode
26    ScreenWidth: LongInt = 800;
27    ScreenHeight: LongInt = 600;
28  
29  var
30    vi_Counter1, vi_Counter2: Integer;
31    NewFormWidth: Integer;
32  
33  begin
34    Application.Initialize;
35    Application.CreateForm(TForm1, Form1);
36    Application.CreateForm(TForm2, Form2);
37    NewFormWidth := GetSystemMetrics(0);
38  
39    with Application do
40      for vi_Counter1 := 0 to ComponentCount - 1 do
41      begin
42        //Find all the Auto-create forms
43        if Components[vi_Counter1] is TForm then
44          with (Components[vi_Counter1] as TForm) do
45          begin
46            Scaled := True;
47            if screen.Width <> ScreenWidth then
48            begin
49              Height := longint(Height) * longint(screen.Height) div
50                ScreenHeight;
51              Width := longint(Width) * longint(screen.Width) div
52                ScreenWidth;
53              ScaleBy(screen.Width, ScreenWidth);
54  
55              //Now Scale the Formīs componentīs Font
56              for vi_Counter2 := 0 to ControlCount - 1 do
57                with Components[vi_Counter2] do
58                  //Use RTTI information to find for a Font property
59                  if GetPropInfo(ClassInfo, 'font') <> nil then
60                    Font.Size := (NewFormWidth div ScreenWidth)
61                      * font.Size;
62            end;
63          end;
64      end;
65    Application.Run;
66  end.


finally some aditional considerations: 

You will have to scale every form create on the fly. 
Use only TrueType fonts, not Bitmapped fonts to avoid problems. 
Donīt set the Formīs Position property to poDesigned, when scalling it could be off 
the screen. 
Don't change the PixelsPerInch property of the form. 
Don't crowd controls on the form - leave at least 4 pixels between controls, so that a one pixel change in border  locations (due to scaling) won't show up as ugly overlapping  controls.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC