1

My application is System DPI aware and I would like to have some parts of UI (some child controls) to be bitmap scaled by OS, since we do not want them to be Highdpi aware.

It is possible to set secondary dialogs/windows to be DPI Unaware and that works as expected. But is it possible to do the same for child controls which are docked?

This is the sample code I tried, but the child control(sampleContainerControl) is created as System Aware only.

SetThreadDpiHostingBehavior(DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED);
DPI_AWARENESS_CONTEXT previousDpiContext = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_UNAWARE);

sampleContainerControl = new SampleContainerControl();

sampleContainerControl.Text = "Bitmap scaling Controls Editor";

sampleContainerControl.Dock = DockStyle.Fill;

tabPage.Controls.Add(sampleContainerControl);

SetThreadDpiAwarenessContext(previousDpiContext);

Is there anything that I am missing? As per the link below, it should be possible to create a child control in a different DPI mode. https://learn.microsoft.com/en-us/visualstudio/extensibility/ux-guidelines/per-monitor-awareness-extenders?view=vs-2019&viewFallbackFrom=vs-2019Microsoft.VisualStudio.DpiAwareness#test-your-extensions-for-pma-issues

Please share your experiences or thoughts.

(.net version used is 4.8)

theduck
  • 2,589
  • 13
  • 17
  • 23
Twinkle
  • 11
  • 2
  • Read the notes here: [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/a/50276714/7444103) – Jimi Dec 09 '19 at 13:14
  • Jimi, thanks for the response. What I am looking for is an option to make a child control of a form to be DPI unaware, Thread level disabling while creating an embedded child control is not working as I mentioned above. Assembly level disabling using [assembly: System.Windows.Media.DisableDpiAwareness] works only for WPF applications as per the documentation – Twinkle Dec 10 '19 at 07:36
  • That depends on OS version. Windows 10 1703 and newer allow child controls to have different DPI avareness from their parents, if your app has correct manifest. On older versions of windows, you will not be able to get support from system, but maybe will be able to acchive similar results using hacks. – Torbins Dec 17 '19 at 11:54
  • @Torbins How does this work? The only function I am aware of is SetThreadDpiAwarenessContext, but UI would always be rendered by the main thread. I would like to show all of application as dpi unaware (automatically scaled) and only one component in a separate dialog (ReportViewer) as dpi aware (unscaled - since this is broken in ReportViewer). – Andreas Reiff Apr 20 '20 at 18:39
  • Looks like my memory has failed me. But if you have separate dialog, then you can change behavior for whole dialog. Here they show example with ChooseFont: https://blogs.windows.com/windowsdeveloper/2016/10/24/high-dpi-scaling-improvements-for-desktop-applications-and-mixed-mode-dpi-scaling-in-the-windows-10-anniversary-update/ – Torbins Apr 23 '20 at 17:24

0 Answers0