Jump to content
Sign in to follow this  
billionjk

Why the size of the component create at runtime does not equal the design time?

Recommended Posts

I created a simple project with one panel and one button in Form. Click on the button will create a panel component with the same size as the panel at design time. But why the result of the panel that crates at runtime is smaller than the panel created at design time? I'm using Delphi 10.4.2

 

pnl001.thumb.png.34a115b8a38d0d7e844705e523474e62.png

 

The size of Panel1 is 250x350 pixels. I set the size of pnlRuntime to 250x350 pixels same as Panel1.

procedure TForm1.Button1Click(Sender: TObject);
var
  pnlRuntime: TPanel;
begin
  pnlRuntime := TPanel.Create(Form1);
  pnlRuntime.Parent := Form1;
  pnlRuntime.left := 265;
  pnlRuntime.top := 8;
  pnlRuntime.Height := 350;
  pnlRuntime.Width := 250;
end;

When running the project and clicking Button1. Why the size of the new panel is smaller than Panel1?

 

pnl002.thumb.png.b9a6dff5b57503cc5d19b0c8563b2cf9.png

Edited by billionjk

Share this post


Link to post
1 minute ago, dwrbudr said:

What is the DPI your monitor runs at?

How to check it? I don't know about DPI.

Share this post


Link to post

Try 

pnlRuntime.Height := MulDiv(350, Screen.PixelsPerInch, 96);

 

Share this post


Link to post
procedure TForm1.Button1Click(Sender: TObject);
var
  pnlRuntime: TPanel;
begin
  pnlRuntime := TPanel.Create(Form1);
  pnlRuntime.Parent := Form1;
  pnlRuntime.left := 265;
  pnlRuntime.top := 8;
//  pnlRuntime.Height := 350;
//  pnlRuntime.Width := 250;
  pnlRuntime.Height := MulDiv(350, Screen.PixelsPerInch, 96);
  pnlRuntime.Width := MulDiv(250, Screen.PixelsPerInch, 96);
end;

 

After changing the code as dwrbubr suggested. The size going equals the design time. How about the position? and How about the third parameter of 96 in MulDiv(350, Screen.PixelsPerInch, 96)? 

 

pnl003.thumb.png.bb1312a2f690f26748815a7fc4cf2754.png

Share this post


Link to post

Use the same calculations for Left and Top. 96 is the default screen pixels per inch at 100% scaling, e.g. Screen.DefaultPixelsPerInch

Check your display options in Windows to see what screen scaling you're using, probably 125% or 150%

Share this post


Link to post
50 minutes ago, dwrbudr said:

Use the same calculations for Left and Top. 96 is the default screen pixels per inch at 100% scaling, e.g. Screen.DefaultPixelsPerInch

Check your display options in Windows to see what screen scaling you're using, probably 125% or 150%

After checking my screen scaling it was set to 125% and I changed the scaling to 100%, 150% and 175% the components on the form are scaled correcting. Thank you so much.

 

1706510411441_0.thumb.jpg.dfa56a9a3ef454f7b318f209e168dc9c.jpg

1706510437757_0.thumb.jpg.5a57d5d4448eb754e9340844405678a4.jpg

1706510464647.thumb.jpg.56d0f8bb3930ead5ef587edaa89e9aa2.jpg

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×