Avatar billede Slettet bruger
10. oktober 2001 - 13:31 Der er 1 kommentar og
2 løsninger

Skalering af forms og indhold

Hvordan får man en form\'s indhold til at skalere alt efter hvor meget man forstørrer/formindsker formen. Fx hvis man under run-time gør formen lidt mindre skulle samtlige labels, editfelter, kanpper osv gerne følge med. Jeg går ud fra at det er MEGET besværtligt. Hjælp
Avatar billede martinlind Nybegynder
10. oktober 2001 - 13:42 #1
Der er noget med at der er en func. der heder ScaleBy på alle controls, og hvis du får den til at funke er det bare at løbe controls-listen igennem og gøre det, problemet ligger i at få den til at virker, jeg har ikke prøvet
Avatar billede morten_s Nybegynder
10. oktober 2001 - 14:42 #2
Prøv at kig lidt på denne kode som er hentet fra:
http://www.delphi3000.com/articles/article_1482.asp



You have to modify your project´s DPR file to acomplish that:

//MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
// Modify your projects code to achieve resolution independent
// applications. I have found that this trick only works for
// resolutions greater than the resolution you design the forms, for
// example if you design at 800x600 you can use your application at
// a resolution of 1024 x 768 or greater.
// However it won´t run fine at 640x480 (altough, nowadays I don´t
// kwonw many people with thatv resolution, so I think 800X600 is
// fine)
//MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW

program TestResolution;

uses
  Forms,
  Dialogs,
  Classes,
  TypInfo,
  Windows,
  Unit1 in \'Unit1.pas\' {Form1},
  Unit2 in \'Unit2.pas\' {Form2};

{$R *.RES}

const
  //If form is designed in 800 x 600 mode
  ScreenWidth: LongInt = 800;
  ScreenHeight: LongInt = 600;

var
  vi_Counter1, vi_Counter2: Integer;
  NewFormWidth: Integer;

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  NewFormWidth := GetSystemMetrics(0);

  with Application do
    for vi_Counter1 := 0 to ComponentCount-1 do
    begin
      //Find all the Auto-create forms
      if Components[vi_Counter1]is TForm then
        with (Components[vi_Counter1]as TForm)do
        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);

            //Now Scale the Form´s component´s Font
            for vi_Counter2 := 0 to ControlCount-1 do
              with Components[vi_Counter2] do
                //Use RTTI information to find for a Font property
                if GetPropInfo(ClassInfo, \'font\')<>nil then
                  Font.Size := (NewFormWidth div ScreenWidth)
                              *font.Size;
          end;
        end;
    end;
  Application.Run;
end.
//MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW

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.   

Avatar billede Slettet bruger
10. oktober 2001 - 15:38 #3
> Morten S > Det skal også være RUNTIME, så dit ellers glimrende eksempel funger ik :(
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester