Business Directory
Trade Forum
Vision 2000
Delphi
Domain Rates
Search
Music
Opinion Award
About
FeedBack
Quit


Delphi Tips & Tricks

| Tips & Tricks | Bug List | Cool Delphi Sites |
| Connectivity | Delphi 2.0 Features | Internet |

Changing Forms according to Screen Resolution

When designing forms, it is sometimes helpful to write the code so that the screen and all of its objects are displayed at the same size no matter what the screen resolution is. Here is some code to show how that is done:

implementation
const
    ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}
    ScreenHeight: LongInt = 600;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
    scaled := true;
    if (screen.width <> ScreenWidth) then
    begin
	height := longint(height) * longint(screen.height) DIV ScreenHeight;
	width := longint(width) * longint(screen.width) DIV ScreenWidth;
	scaleBy(screen.width, ScreenWidth);
    end;
end;

Then, you will want to have something that checks to see that the font sizes are OK. Before you change the font's size, you would need to ensure the object actually has a font property by checking the RTTI. This can be done as follows:

uses typinfo; {Add this to your USES statement.}

var
    i: integer;
begin
    for i := componentCount - 1 downto 0 do
    	with components[i] do
	begin
	    if GetPropInfo(ClassInfo, 'font') <> nil then
		font.size := (NewFormWidth DIV OldFormWidth) * font.size;
	end;
end;

{This is the long way to do the same thing.}
var
    i: integer;
    p: PPropInfo;
begin
    for i := componentCount - 1 downto 0 do
	with components[i] do
	begin
	    p := GetPropInfo(ClassInfo, 'font');
	    if assigned(p) then
		font.size := (NewFormWidth DIV OldFormWidth) * font.size;
	end;
end;

| Borland Delphi | About the Authors | Home |

For Queries Mail To Webmaster

Copyright © 1996 Asylum Software Pvt. Ltd. This is an ASPL production.
Produced in conjunction with ASPL DELPHI TEAM.
Last revised November 27, 1996.