Search code examples
c#wpfwinformsdpi-aware

Winform window gets shrinked when lauched through WPF Application


I have created WPF application . In this application

  1. I am launching win form exe.
  2. Later make WPF window as parent of this win form.
  3. when I execute this application with present resolution . things work fine

But when I launch same thing through 4K Monitor(3840 * 2100) form size gets reduced.

I tried following things .

  1. Making win form Size to window. Maximized.
  2. Creating WPF manifest and uncommenting DPIaware to make WPF application DPIaware.
  3. manipulating size of parent window.

Any help or suggestion would be helpful. (FYI : while I tried to launch same exe from WinForms I don't see this issue).

Code snippett

/* mainwindow.xaml.cs*/
    var procInfo = new System.Diagnostics.ProcessStartInfo(ExeName, arguments);
    // Start the process
    var ProcessObj = System.Diagnostics.Process.Start(procInfo);
    var helper = new WindowInteropHelper(Window.GetWindow(this.grid1));
    SetParent(ProcessHandler, helper.Handle);

/* App.manifest */
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
  </application>
 
/*assemblyinfo.cs*/
[assembly: System.Windows.Media.DisableDpiAwareness]

Solution

  • Make WPF dpi unaware using any of the following solutions:

        /* App.manifest *
           <application xmlns="urn:schemas-microsoft-com:asm.v3">
           <windowsSettings>
              <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>
        </windowsSettings>
      </application>
     
    

    or

        /*assemblyinfo.cs*/
         [assembly: System.Windows.Media.DisableDpiAwareness]