【问题标题】:Winform window gets shrinked when lauched through WPF Application通过 WPF 应用程序启动时,Winform 窗口会缩小
【发布时间】:2021-02-25 05:16:09
【问题描述】:

我已经创建了 WPF 应用程序。在这个应用程序中

  1. 我正在启动 win form exe。
  2. 稍后将 WPF 窗口设为此 win 表单的父级。
  3. 当我以当前分辨率执行此应用程序时。一切正常

但是当我通过 4K Monitor(3840 * 2100) 启动相同的东西时,表单大小会减小。

我尝试了以下事情。

  1. 将 win 窗体大小设置为窗口。最大化。
  2. 创建 WPF 清单并取消注释 DPIaware 以使 WPF 应用程序具有 DPIaware。
  3. 控制父窗口的大小。

任何帮助或建议都会有所帮助。 (仅供参考:当我尝试从 WinForms 启动相同的 exe 时,我没有看到这个问题)。

代码 sn-pt

/* 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]

【问题讨论】:

    标签: c# wpf winforms dpi-aware


    【解决方案1】:

    使用以下任何解决方案使 WPF dpi 不感知:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2022-01-14
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多