Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

I can scale my application smaller, but now i want to go to a bigger scale and then back my normal scale

I have am trying scaling my application, make it smaller, normal size, bigger and back to normal size again
well thats what im trying to achieve but my code isnt working properly.

It can go smaller, but it cant go bigger or back to the original size. Could someone look at it?

var
CurrentScreenWidth := Screen.Width;
CurrentScreenHeight := Screen.Height;
OriginalScreenWidth := Screen.Width;
OriginalScreenHeight := Screen.Height;


Procedure TForm1.Smaller1Click(Sender: TObject);
begin
CurrentScreenWidth := CurrentScreenWidth + 100;
CurrentScreenHeight := CurrentScreenHeight + 100;
Form1.ScaleForm(Form1,CurrentScreenWidth,CurrentScreenHeight);
end;

procedure TForm1.ScaleForm(F: TForm; ScreenWidth, ScreenHeight: Integer);
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;

   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;

Procedure TForm1.Bigger1Click(Sender: TObject);
begin
CurrentScreenWidth := CurrentScreenWidth - 100;
CurrentScreenHeight := CurrentScreenHeight - 100;
Form1.ScaleForm(Form1,CurrentScreenWidth,CurrentScreenHeight);
end;

How do I go smaller and bigger and back to the original size again.
If i go smaller that works, but if i go bigger it keep going smaller.

Weird?

Ben
0
Alpha_AI
Asked:
Alpha_AI
2 Solutions
 
TheRealLokiSenior DeveloperCommented:
The following works fine for me

procedure TForm1.bGoSmallerClick(Sender: TObject);
begin
  Form1.ScaleBy(75, 100);
end;

procedure TForm1.bGoBiggerClick(Sender: TObject);
begin
  Form1.ScaleBy(100, 75);
end;
0
 
ErrroCommented:
procedure TForm1.SmallerClick(Sender: TObject);
begin
    CurrentScreenWidth := CurrentScreenWidth - 100;
    CurrentScreenHeight := CurrentScreenHeight - 100;
    Form1.ScaleForm(Form1, CurrentScreenWidth, CurrentScreenHeight);
end;

procedure TForm1.ScaleForm(F: TForm; ScreenWidth, ScreenHeight: Integer);
var
    NewFormWidth: Integer;
begin
    F.Scaled := True;
    F.AutoScroll := False;
    F.Position := poScreenCenter;
    F.Font.Name := 'Tahoma';

    NewFormWidth := Round(ScreenWidth * ScaleV);

    F.ScaleBy(NewFormWidth, F.Width);
end;

procedure TForm1.biggerClick(Sender: TObject);
begin
    CurrentScreenWidth := CurrentScreenWidth + 100;
    CurrentScreenHeight := CurrentScreenHeight + 100;
    Form1.ScaleForm(Form1, CurrentScreenWidth, CurrentScreenHeight);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    CurrentScreenWidth := Screen.Width;
    CurrentScreenHeight := Screen.Height;
    OriginalScreenWidth := Screen.Width;
    OriginalScreenHeight := Screen.Height;

    ScaleV := Form1.Width / Screen.Width;
end;


it works fine
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now