Recent

Author Topic: [SOLVED] Scaling. Windows 7 / 10  (Read 2471 times)

Petrus Vorster

  • Full Member
  • ***
  • Posts: 220
[SOLVED] Scaling. Windows 7 / 10
« on: December 30, 2025, 01:10:48 pm »
Hi All. AGAIN.  :'(

I have build a number of tools on the one work PC. Windows 7 64 bit.
I gave it to someone on WIN10 and I nearly fainted when I saw how bad it looks on Windows 10.

Images on buttons and menus, suddenly overlap the text, icons that was tiny is now so large it exceeds the frame etc. It just looks miserable.

I have to work on the Win7 machine to see if it will run for the users with older equipment.

Obviously, I have missed something very big.

-Peter
« Last Edit: January 02, 2026, 06:35:23 am by Petrus Vorster »

LeP

  • Full Member
  • ***
  • Posts: 117
Re: Scaling. Windows 7 / 10
« Reply #1 on: December 30, 2025, 03:36:13 pm »
You've provided too little information (virtually none of it useful) to be able to offer any advice.
To develop applications for different OS/hardware, you need to pay attention to all the necessary details and variations.
Just to give you a few examples: monitor ratio (4/3 ... 10/9), supported resolutions (VGA ... FULL HD ... 4K), upscaling, DPI/HDPI (96 ... 240), etc.

dseligo

  • Hero Member
  • *****
  • Posts: 1653
Re: Scaling. Windows 7 / 10
« Reply #2 on: December 30, 2025, 03:47:42 pm »
Check Project/Project Options.
You should have checked 'Use LCL scaling (Hi-DPI)' and 'Use manifest resource'. Set 'DPI awareness' to 'on (True)'.

Boleeman

  • Hero Member
  • *****
  • Posts: 1103
Re: Scaling. Windows 7 / 10
« Reply #3 on: January 01, 2026, 04:34:53 am »
I noticed the same problem as well.

I have checked 'Use LCL scaling (Hi-DPI)' and 'Use manifest resource'. Set 'DPI awareness' to 'on (True)' but the problem persists.

Noticed that on my AMD CPU Laptop everything appears OK, but when running on Intel based CPU laptop the GUI is messed up. When I uncheck 'Use LCL scaling (Hi-DPI)' in Set 'DPI awareness' , then the GUI (user interface appears normal). Somehow the CPU type changes the appearance of the form?

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 364
  • I use FPC [main] 💪🐯💪
Re: Scaling. Windows 7 / 10
« Reply #4 on: January 01, 2026, 05:04:25 am »
I know that this person is very knowledgeable about the intricacies of scaling, and he attempted to make scaling in Lazarus perfect through a series of patches

But for that to happen, this first patch needs to be accepted. In its current form, or at least reworked, without changing its functionality and behavior

It's a shame that its merge was blocked

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41428
I may seem rude - please don't take it personally

Petrus Vorster

  • Full Member
  • ***
  • Posts: 220
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #5 on: January 02, 2026, 06:39:17 am »
Hi All

According to Microsoft's AI response, there is a known problem with image scaling using a Timagelist in Windows7, and running it on WIn10.

Since it appears that we are actually going to roll out new laptops with Win10, I am just going to recompile, adjust and re-build on win10.
Its just going to be out-of-luck for those still stuck on win7.
I am not dragging my name through the mud with apps that looks like its been made by a kindergarden.

Thank you as always for your help.

-Peter

wp

  • Hero Member
  • *****
  • Posts: 13350
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #6 on: January 02, 2026, 12:08:21 pm »
I am very sure that you are doing something wrong. To all my knowledge the Lazarus IDE looks (almost) correct in all Windows versions at any resolution, and this is an application written in a way to take advantage of the LCL scaling mechanism.

You still did not provide any information about your system as required above: What is the resolution (in pixels per inch) of both of the Win7 and Win10 systems? Which value is used in "Accessibility" > "TextSize" (in Win 11, I think it did not yet exist in Win7)? If you used the accessibility settings for increasing text size on a high-res screen you can get significant overlap of controls when they are positioned manually rather than by using anchoring techniques.

Test the attached project in which all controls are positioned by anchoring and the image is extracted from a scaled image list (ImageList.Scaled = true). I checked on Win11 and Win7 at various pixels-per-inch and accessibility-textsize settings - in every case the scaling is correct within the known limitations (only text scaling by accessibility settings, controls are only scaled in the dimensions handled by auto-sizing) - see the screenshots in the attachment.

Petrus Vorster

  • Full Member
  • ***
  • Posts: 220
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #7 on: January 02, 2026, 02:53:19 pm »
Hi

I have all the right click and ticks as the gurus suggested above.
I think it may be because I used the SPK toolbar and Microsoft said its a known issue.

I also perhaps did not provide sufficient info.

Other controls appear reasonably close to correct.
The Bitbtn has an issue and the SPK toolbar. That was the major problem.
I just opened the project in Windows10, made one adjustment and the SPKtoolbar redrawn itself correctly.
The buttons I had to reduce the Image size a little.

You also nailed the issue with the text size.

Anchoring was correct. The only wrong anchoring is where I anchored something to the wrong control.
This is a great forum with a lot of help.

-Peter

wp

  • Hero Member
  • *****
  • Posts: 13350
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #8 on: January 02, 2026, 03:47:47 pm »
Not sure: Didn't I fix a scaling issue in SpkToolbar recently? Maybe install the CCR version from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/spktoolbar/.

dseligo

  • Hero Member
  • *****
  • Posts: 1653
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #9 on: January 02, 2026, 07:06:08 pm »
Not sure: Didn't I fix a scaling issue in SpkToolbar recently? Maybe install the CCR version from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/spktoolbar/.

I am pretty sure that this is his problem.

Is it possible to put corrected version into OPM?

P.S.: And if this is the case, then the other controls looks fine and he should have mention that.
« Last Edit: January 02, 2026, 07:17:03 pm by dseligo »

Boleeman

  • Hero Member
  • *****
  • Posts: 1103
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #10 on: January 04, 2026, 12:49:28 am »
Just to show the scaling problem that I seem to have when running on different laptops.

Program compiled on 1 Acer AMD Windows 10 64Bit (Lazarus 32Bit compiler) laptop with scaling enabled:
Everything centered and TPaintbox is fully shown.

Then I run it on 2 other laptops ( Acer AMD Win 10, Acer Intel Win 11) (Lazarus 64Bit compiler) with scaling enabled:
Rendering not centered and TPaintbox is not fully shown (in other programs the rendering seems too big for the canvas).

When I disable the scaling, then the full TPainbox is shown.

Noticed:
If I have a OnResize event then the rendering refreshes and becomes centered in other programs that I have made.
« Last Edit: January 04, 2026, 01:51:48 am by Boleeman »

wp

  • Hero Member
  • *****
  • Posts: 13350
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #11 on: January 04, 2026, 08:00:19 pm »
I am attaching a version of your project which scales correctly.

Quote
Code: [Select]
  w := 800 + Panel1.Width;
  Width := w;
  Height := w - Panel1.Width;
  t := 0;
Don't know what you want to achieve with this in the OnCreate handler of the form, but the large literal numeric value 800 certainly is a severe issue for correct scaling because the corresponding dimension does not change when the pixel density changes. Since you add 800 to the panel width and then assign it to the width of the form, I guess you want the size of the Paintbox to be 800x800? For such a case, I would set the Paintbox.Constraints.MinWidth and .MaxWidth to 800 and the .MinHeight and .MaxHeight as well - this would freeze the size of the paintbox and protect it from incidental size changes.

Nevertheless, I skipped this detail in the modified demo because I found another issue: You do not scale the size of the buffer bitmap - this is an object that you created and you have the responsibility to scale it. You create the bitmap in the OnCreate event of the form, and you also define the size variable w there. But OnCreate often is too early when size calculations are involved because the form does not yet have a parent at this early state and thus sizing operations are delayed.

You can postpone your bitmap creation to a later state, I prefer the OnActivate event (along with a status variable to avoid multiple calls):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   { Don't use unscaled dimensions!
  4.   w := 800 + Panel1.Width;
  5.   Width := w;
  6.   Height := w - Panel1.Width;
  7.    }
  8.   t := 0;
  9. // The Paintbox has not yet been scaled here, the bmp will be too small on a high-dpi screen!
  10. //  bmp := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height, BGRABlack);
  11.   Timer1.Interval := 16; // ~60 FPS
  12.   Timer1.Enabled := True;
  13.  
  14.   trkSpeedAdjust.Max := 100;
  15.   trkSpeedAdjust.Position := 8; // default speed
  16.  
  17.   FActivated := false;  // a boolean variable in TForm1
  18. end;
  19.  
  20. procedure TForm1.FormActivate(Sender: TObject);
  21. begin
  22.   if not FActivated then
  23.   begin
  24.     FActivated := true;
  25.     // LCLScaling has been completed here --> the bitmap can get its correct size.
  26.     bmp := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height, BGRABlack);
  27.   end;
  28. end;

This solution, although simple, has a disadvantage: When you have two monitors with different resolutions and drag the form over to the other monitor with the different ppi LCLScaling will change the size of the paintbox but your buffer bitmap will not notice it and remain at its old size - you will either have a non-centered waterfall or the image will not cover the entire paintbox.

There is a procedure AutoAdjustLayout which is called whenever the monitor ppi changes. This is a rather general procedure, the usual way for user-defined scaling is to override the DoAutoAdjustLayout method which is called from there for each control. Since the Paintbox has been already scaled by the ancestor method simple reset the size of the buffer bitmap here:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
  2.   const AXProportion, AYProportion: Double);
  3. begin
  4.   inherited;
  5.   // The PaintBox has already been resized (by "inherited") - we must update the size of the buffer bitmap
  6.   bmp.SetSize(Paintbox1.Width, Paintbox1.Height);
  7. end;
Since the AutoAdjustLayout mechanism is triggered also at program start in case of different resolutions, you can keep creation of the bitmap in the OnCreate handler.

I moved the variable w (which is the Paintbox.Width, isn't it?) into the Paintbox.OnPaint handler so that is requires no extra handling. If you don't want that, update w whenever you change the bmp size.

In the screenshots of the modified demo, taken at 96 ppi and 144 ppi, you can see that there are more cascades of the waterfall at the higher resolution. This is because your drawing code uses unscaled numbers in the OnPaint handler. It's a bit tricky to find out the relevant numbers in this specific project- I did not go into this detail. Call Scale96ToForm for the number that you want to scale from 96ppi to the current ppi.
« Last Edit: January 04, 2026, 08:10:06 pm by wp »

Boleeman

  • Hero Member
  • *****
  • Posts: 1103
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #12 on: January 06, 2026, 12:48:53 am »
Many thank WP for looking at an old code example illustrating the scaling issue.

I sometimes give my programs to people to test out and had noticed that on some laptops the scaling was off.

The main aim of the sample program was to have the canvas square, by taking into account the width of the TPanel. I tried out your sample code with TForm1.DoAutoAdjustLayout. That seemed to work, although what threw me off was that the top rendering of the waterfall was not perfectly centered.

Thanks for taking the time to look at the scaling issue that I have had. I thought somehow it was related to compiling to 32 bits or CPU related (Intel and AMD differences) but it seems it's monitor scaling on different computers.

I tested out your suggestions on another program and found moving bmp := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height, BGRABlack);  into procedure TForm1.FormActivate created an access violation, so I kept it in procedure TForm1.FormCreate

As seen in the png below, the TPaintBox/Tbgrabmp rendering is not offset but the rendering size is bigger (the tips of the lotus flower are cut off)

I thought the main point of setting LCL scaling was so that the rendered image appeared consistent on every computer, but as you pointed out in the screenshots of the modified demo, taken at 96 ppi and 144 ppi, there are more cascades of the waterfall at the higher resolution.

Wonder what solution is there to make the renderings a consistent size regardless of dpi setting?


Thanks WP
for taking the time to find a solution to the "controls out of whack" on startup issue.
« Last Edit: January 06, 2026, 12:57:43 am by Boleeman »

wp

  • Hero Member
  • *****
  • Posts: 13350
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #13 on: January 06, 2026, 01:24:42 am »
Your drawings are generated by some kind of math based on control parameters. You must make sure that these parameters are scaled as well whenever the screen resoluition changes.

Suppose you want to draw a sine wave, a single period over the entire square paintbox of width and height 800. For each pixel at horizontal coordinate x, the vertical y value then is y := 400*(1 + sin(x/400 * pi)). When you now increase the size of the paintbox by 50% to 1200 and keep the formula, the wave suddenly does not fill the paintbox any more - you must rescale the equation to y := 600 *(1 + sin(x/600 * pi)).

The same thing happens with LCL scaling: the paintbox on which you designed the drawing becomes bigger by the ratio of the ppi values. You can keep the original formula by replacing the relevant parameters by scaled values: y := Scale96ToForm(400) * (1 + sin(x/Scale96ToForm(400) * pi)) - now the sine wave again fills the entire paintbox with a single period from left to right.

Scale96ToForm assumes that the value given as parameter is valid for a resolution of 96 ppi (100%). When the application runs on a high-dpi monitor it multiplies the parameter by the ratio of current ppi to 96.

Boleeman

  • Hero Member
  • *****
  • Posts: 1103
Re: [SOLVED] Scaling. Windows 7 / 10
« Reply #14 on: January 06, 2026, 02:21:46 am »
Thanks for that reply WP.

That flower example uses TBGRACanvas2D from TBgrabmp with localCanvas.translate and localCanvas.rotate and localCanvas.moveTo and localCanvas.lineTo so perhaps there is something similar to Scale96To in TBGRACanvas2D ?

 

TinyPortal © 2005-2018