c# - 通过 WPF 应用程序启动时 Winform 窗口会缩小

标签 c# wpf winforms dpi-aware

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

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

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

我尝试了以下操作。

  1. 将 win 窗体大小设置为窗口大小。最大化。
  2. 创建 WPF list 并取消注释 DPIaware 以使 WPF 应用程序 DPIaware。
  3. 操纵父窗口的大小。

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

代码片段

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

最佳答案

使用以下任一解决方案使 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]

关于c# - 通过 WPF 应用程序启动时 Winform 窗口会缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64816816/

相关文章:

wpf - 为什么在持久化的 WPF RichTextBox 中有自复制的大括号?

WPf : Binding with more than one property at a time

c# - 通过PHP脚本隧道连接MySQL

c# - 使用网络响应加载网络浏览器

c# - 如何暂停 DataTable 通知或数据绑定(bind)以防止 UI 更新

c# - Windows Phone 8.1 上的 MvvmCross 向后导航

c# - 在 app.config 中设置值 - 没有对程序文件的写入权限

c# - .Net PropertyGrid DropDownList - 返回值不同于显示值

c# - 如何保持自动回传的滚动位置?

wpf - TreeViewItem.Header 内有 Grid