Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   Form Resolution independent (http://www.delphipages.com/forum/showthread.php?t=211758)

delphimpd 02-07-2012 08:17 PM

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;


Marsheng 07-03-2012 12:13 PM

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

delphimpd 07-06-2012 02:27 PM

Hi Sorry, never worked for me neither.

Sorry

jm78 07-11-2012 06:57 AM

Quote:

Originally Posted by Marsheng (Post 222637)
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);

Marsheng 07-11-2012 11:28 PM

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.

.

Marsheng 07-14-2012 08:58 AM

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;



All times are GMT. The time now is 05:29 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2014, vBulletin Solutions, Inc.