Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2012, 08:17 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 648
Default Form Resolution independent

Hi All and thanks for your help.

I was wondering if you guys can help me out on this code.

I used to program my Applications in Delphi 7 however a while back I updagraded to 2010. I own a copy of ElasticForm which is in charge of handeling all type of Screen resolution changes, however, ElasticForm is not compatible with 2010. I tried to contact the Component developer but no answer from her.

I found this code out there, which is suposed to take care of resolution changes and make all components inside the form resolution independant, however it is not working for me, I am sure that I am not doing things right.

Perhaps you have a better solution, or a better explanation of how to use the below code the right way.

Thanks again for your help.


Here is the code



Code:
procedure ScaleForm(F: TForm; ScreenWidth, ScreenHeight: LongInt) ;
begin
   F.Scaled := True;
   F.AutoScroll := False;
   F.Position := poScreenCenter;
   F.Font.Name := 'Arial';
   if (Screen.Width <> ScreenWidth) then begin
     F.Height :=
         LongInt(F.Height) * LongInt(Screen.Height)
         div ScreenHeight;
     F.Width :=
         LongInt(F.Width) * LongInt(Screen.Width)
         div ScreenWidth;
     F.ScaleBy(Screen.Width,ScreenWidth) ;
   end;
end;
Reply With Quote
  #2  
Old 07-03-2012, 12:13 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

I've tried fMain.scaleby(120,120);
But nothing happens. Tried a button, panel but non change size. Is there something i need to activate? Scaled is set to true. Delphi 6
Reply With Quote
  #3  
Old 07-06-2012, 02:27 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 648
Default

Hi Sorry, never worked for me neither.

Sorry
Reply With Quote
  #4  
Old 07-11-2012, 06:57 AM
jm78 jm78 is offline
Member
 
Join Date: Sep 2007
Posts: 36
Default

Quote:
Originally Posted by Marsheng View Post
I've tried fMain.scaleby(120,120);
But nothing happens.
Not sure what is expected to happen?

Anyway, few years ago I started getting feedback about problems with some resolutions. Not all components would fit into window. I added this line to every formcreate and I haven't had problems since. (D7/D2006)

if pixelsperinch>120 then scaleby(120,120);
Reply With Quote
  #5  
Old 07-11-2012, 11:28 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

After trying heaps of options with ScaleBy and nothing happening, I finally found a tutorial on the web which showed my the error .

ScaleBy(M,D:Integer)

You would think that M and D would be height and width, but no, M is new and D is original. If you want to scale something by 20% you enter ScaleBy(120,100) or ScaleBy(60,50) or (30,25) Make sense. Unless you are smoking the same weed as the Delphi developers are, it won't. Now read the help ? Any better - No.

If some one is not intelligent enough to program ScaleBy(Round(NewSize/OldSize)) then they should be banned from using Delphi.

Saying all that, ScaleBy only does panels and other static bits. It does not do DBGrids. For that you really have no option left other than recoding each page with each grid for each screen resolution.

You would thinks that a 10 + year old and very expensive developmemnt package would cater for different resolutions but no.

It Sucks.


I've tried 3 third party scaling packages and all have issues.

.
Reply With Quote
  #6  
Old 07-14-2012, 08:58 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

Hopefully I'm not on the wrong path but this works well enough.

Is there a way to take all visible elements on a form and apply a scaling factor programatically instead of one by one as below?

Code:
procedure TfMain.Button1Click(Sender: TObject);
var
   rWidScale,rHeiScale:real;
begin
   rWidScale:=Screen.Width/fMain.Width;  // Scale to full screen
   rHeiScale:=Screen.Height/fMain.Height;
   fMain.Left:=0;  // Full screen
   fMain.Top:=0;
   Button1.Top:=Round(Button1.Top*rHeiScale);
   Button1.Left:=Round(Button1.Left*rHeiScale);
   Button1.Width:=Round(Button1.Width*rHeiScale);
   Button1.Height:=Round(Button1.Height*rHeiScale);
   Button1.Font.Size:=Round(Button1.Font.Size*rWidScale);
   fMain.Width:=Round(fMain.Width*rWidScale);
   fMain.Height:=Round(fMain.Height*rHeiScale);
   DBGrid1.Width:=Round(dbGrid1.Width*rWidScale);
   DBGrid1.Height:=Round(dbGrid1.Height*rHeiScale);
   DBGrid1.Top:=Round(dbGrid1.Top*rHeiScale);
   DBGrid1.Left:=Round(dbGrid1.Left*rWidScale);
   DBGrid1.Font.Size:=Round(dbGrid1.Font.Size*rWidScale);
end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.