Monday, August 12, 2019

C# Winforms Rendering Differences on Windows 7 vs Win10 with Scale Set at 150%

As an active Windows developer of a number of WinForm applications, I always have to be backwards compatible to Windows 7, and hence use .NET 4.0 Framework which run natively on Windows 7 new image. 

But recently, I noticed that my WinForm app was not rendering properly in Windows 10, but was working just fine on Windows 7? What gives, same framework right? 

Here's example of problematic DialogBox not rendering well in Windows 10




Here's example of corrected DialogBox properly rendering in Windows 10




Problem Description


I have a WinForm program that calls another WinForm Text Editor using standard
System.Diagnostics.Process.Start("texteditor.exe"); 
, but in Text Editor a number of dialog boxes would get the squeezed.

But I noticed, if I double-click on the TextEditor.exe directly, the dialog boxes would rendered properly! 

So I then tried run TextEditor.exe from the command line


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Process process = new Process
{
    StartInfo =
    {
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true,
        FileName = "cmd.exe",
        Arguments = "/C texteditor.exe"
    }
};
process.Start();
process.WaitForExit();

Still I go same results, a crunched dialog box.


Solution to Rendering WinForm Apps of Windows 10 with Scaling Factor set to something other than 100% 


The following worked to launch another exe with proper rendering of all dialog boxes in Windows 10.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Process process = new Process
{
    StartInfo =
    {
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true,
        FileName = "Explorer.exe",
        Arguments = "texteditor.exe"
    }
};
process.Start();
process.WaitForExit();



Given in my Windows 10 Display Setting, has Scale and Layout set at 150% which caused the rendering issue. If scale is set to 100% the dialog box renders correctly. But at different scales the dialog box would be crunched.







No comments:

Post a Comment