How to scale tab images in high DPI 4k Windows Form application?

63 views Asked by At

In my Windows Form application I use images from an image list for my tabs. This is configured via Visual Studio 2022, no code written on my side.

Looks fine on a 1920 resolution.

1920 res

However, under 4k the images appear rather small. Any chance to adjust this?

4k

The image list has a setting for the ImageSize of 16,16. If I increase it to 32,32 it appears correct under 4k, but oversized at 1920.

I did try to just change the size at runtime like below, but this leads to no images at all.

int dpiFactor = (int)(this.DeviceDpi / 96.0);
if (dpiFactor >= 2)
{
    Size imageSize = il_Application.ImageSize;
    imageSize.Width *= dpiFactor;
    imageSize.Height *= dpiFactor;
    il_Application.ImageSize = imageSize;
}

The auto-generated code does not contain the size at all, so I assume the scaling takes place at generation time.

il_Application.ColorDepth = ColorDepth.Depth8Bit;
il_Application.ImageStream = (ImageListStreamer)resources.GetObject("il_Application.ImageStream");
il_Application.Tag = "application icons";
il_Application.TransparentColor = Color.Transparent;

Is there a setting to get it automatically scaled like the rest of the application?

Image list

0

There are 0 answers