question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScaleControl is not called anymore at 100% scaling

See original GitHub issue
  • .NET Core Version:
    6.0.101

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:

Some Windows Forms controls require manual scaling by overriding the Control.ScaleControl(SizeF, BoundsSpecified) method.

In .NET Framework applications (tested with dpi awareness enabled in manifest, high dpi auto resizing and PerMonitorV2 support enabled in app.config the ScaleControl method is called by the runtime when InitializeComponent calls ResumeLayout regardless of the users screen scaling.

In .NET 6.0 (tested with HighDpiMode.SystemAware and HighDpiMode.PerMonitorV2) the ScaleControl method is not called anymore when the users screen is scaled at 100% (default). My code from .NET Framework relies on ScaleControl being called for all screen scaling in order to initialize graphics in the right resolution.

Expected behavior:

Windows Forms calls ScaleControl at initialization for every control and even 100% scaling like .NET Framework did in order to maintain compatibility.

If this no-op on machines with regular DPI displays is a performance concern, you should mention this breaking change in the migration guides and ideally create a workaround.

Minimal repro:

  1. Create a new Windows Forms project dotnet new winforms
  2. Add the following code to Form1.cs:
    protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
    {
        BackColor = Color.Aquamarine;

        base.ScaleControl(factor, specified);
    }
  1. Run the application on a device with 100% scaling (96 DPI)
  2. On .NET Framework you would see a blue window, on .NET 6.0 the window stays gray

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
daniel-lerchcommented, Feb 23, 2022

As a workaround for initialization code which depends on scaling I override OnLayout and perform my initialization also there. Because OnLayout is called quite often I check whether initialization has already been done (in my case with a null check). Secondly I check that the scaling factor is one. For all other scaling factor I use ScaleControl as usually.

The previous implementation for .NET Framework was easier but I accept that it has already been somewhat hacky and there I don’t think it’s necessary to provide an alternative here unless other people ask for it.

0reactions
daniel-lerchcommented, Feb 8, 2022

I created a custom list view control with an image list and custom sizing logic for the rows. In ScaleControl I create a new image list with the right scaling from the original and large images. For my custom sizing logic to work, I also save the new row widths which is used later in my resizing logic: View source code

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to relative scale size of User Control? - wpf
How to relative scale size of User Control like image (in image editor). Example (100%):. alt text (source: stegnar.com). Scaled down UC (70%):....
Read more >
Text not scaling - General Discussion
Does anyone have an idea on why text in the VP Annotation does not scale? A 10 Pt letter/number in VP Annotation is...
Read more >
Display map scale | Mapbox GL JS
Display map scale ... Use addControl to add scale to the map.
Read more >
Leaflet - a JavaScript library for interactive maps
Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically,...
Read more >
Hot Tub Things Stain and Scale Control 32 Ounce ...
per 100 gallons of Stain & Scale Control to hot tub water while the pump is running. Allow the water to recirculate overnight...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found