如何避免调整MDIParent表单的大小 [英] How do I avoid MDIParent form from resizing

查看:96
本文介绍了如何避免调整MDIParent表单的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计Windows窗体应用程序.我有一个MDIParent表单,该表单以最大化状态加载,并且也以最大化状态加载其子表单.但是,当我打开OpenFileDialog或任何数据读取器对象时,MDIParent会缩小到具有其所有形式和控件的较小尺寸.

I am designing a Windows Form app. I have an MDIParent form that loads in a maximized state, and loads its child forms in a maximized state as well. However, when I open an OpenFileDialog, or any datareader object, the MDIParent shrinks to a smaller size with all its forms and controls.

此解决方案导致子窗体打开改变尺寸并缩小的mdiform 在我的情况下不适用/不起作用.

This solution Opening child form is causing mdiform to change size and shrink does not apply/work in my situation.

此解决方案也 https://support.microsoft.com/zh-cn/help/967173/restoring-a-maximized-or-minimized-mdi-parent-form-causes-its-height- t 对我不起作用.

Also this solution https://support.microsoft.com/en-nz/help/967173/restoring-a-maximized-or-minimized-mdi-parent-form-causes-its-height-t did not work for me.

某些背景:我几乎在所有WinForm应用程序中都已经看到这种行为,但是我从来不热衷于解决它.当我开始调查时,我能够缩小到上面突出显示的原因.一些帖子将其描述为Windows错误,但是对于我的情况,它已经存在了很长时间,直到屏幕分辨率开始超过1024(VS 2010).我希望这不仅是Windows错误...

Some background: I have seen this behaviour in almost all my WinForm applications but I have never been keen to sort it out. I was able to narrow down to the causes as highlighted above when I started investigate it. Some posts are describing it as a windows bug, but it has existed for as long as the screen resolutions started going above 1024 (VS 2010) for my case. I hoped it is not just a windows bug...

推荐答案

我希望这不仅是Windows错误...

I hoped it is not just a windows bug...

功能,不是bug,但这不是Winforms程序员非常喜欢的.值得注意的是,在过去的几个月中,关于神秘的窗户收缩问题一直存在几个问题.我认为它与Win10 Fall Creators Edition的发布有关.它对旧版Win32 api层进行了深刻的更改,并引起了大量的动荡.

Feature, not a bug, but it is not one that Winforms programmers like very much. Notable is that there have been several questions about mystifying window shrinkage in the past few months. I think it is associated with the release of Win10 Fall Creators edition. It has deep changes to the legacy Win32 api layer and they've caused plenty of upheaval.

在您的特定情况下,功能"由外壳扩展启用.当您使用OpenFileDialog时,它们会注入到您的进程中.执行此操作的人非常非常邪恶,并且执行Shell扩展绝对不能执行的操作.它会调用 SetProcessDPIAware().值得注意的是,它可能是用WPF编写的,它有一个非常sneak琐的后门,可以将自己声明为dpiAware.只需加载PresentationCore程序集就足够了.但不限于WPF代码,任何代码都可以做到这一点,而且很长一段时间以来都没有发现.

In your specific case, the "feature" is enabled by a shell extension. They get injected into your process when you use OpenFileDialog. The one that does this is very, very evil and does something that a shell extension must absolutely never do. It calls SetProcessDPIAware(). Notable is that it might have been written in WPF, it has a very sneaky backdoor to declare itself dpiAware. Just loading the PresentationCore assembly is enough. But not otherwise limited to WPF code, any code can do this and that might have been undetected for a long time.

追逐这个邪恶扩展的一种方法是使用SysInternals的AutoRuns实用程序.它使您可以有选择地禁用扩展名.但是,还有一种程序员的方式,您可以在VS中进行调试.

One way to chase down this evil extension is by using SysInternals' AutoRuns utility. It lets you selectively disable extensions. But there is also a programmer's way, you can debug this in VS.

使用项目>属性>调试选项卡>选中启用本机代码调试"复选框.在旧的VS版本中,名称稍有不同.然后,调试>新断点>功能断点.函数名称= user32!SetProcessDPIAware,语言= C.您可以在不做任何事的WPF应用程序中执行此操作,以确保一切设置正确.为了完整起见,您还可以添加新风格的SetProcessDPIAwareness的断点.

Use Project > Properties > Debug tab > tick the "Enable native code debugging" checkbox. Named slightly different in old VS versions btw. Then Debug > New Breakpoint > Function Breakpoint. Function name = user32!SetProcessDPIAware, Language = C. You can exercise this in a do-nothing WPF app to ensure that everything is set correctly. For completeness you can also add the breakpoint for SetProcessDPIAwareness, the new flavor.

按F5键开始调试并触发OpenFileDialog.ShowDialog()调用.现在应该打断点,使用调试">"Windows">调用堆栈"来查看堆栈跟踪.通常情况下,您看不到任何可识别的内容,因为恶意代码存在于您没有PDB的DLL中.但是DLL的名称和位置(在调试">"Windows">模块"中可见)应该有助于识别与您一起提交错误的人员.如果没有它,可以卸载它.

Press F5 to start debugging and trigger the OpenFileDialog.ShowDialog() call. The breakpoint should now hit, use Debug > Windows > Call Stack to look at the stack trace. You typically will not see anything very recognizable in your case since the evil code lives in a DLL that you don't have a PDB for. But the DLL name and location (visible in Debug > Windows > Modules) ought to be helpful to identify the person you need to file a bug with. Uninstall it if you can live without it.

最后但并非最不重要的是,开始创建具有dpiAware功能的Winforms应用程序变得非常重要,这样这样的错误就永远不会解决.您可以通过将您的应用声明为dpiAware 来启动此功能,从而禁用DPI虚拟化.加上您在代码中需要执行的所有操作,以确保UI设计可以正确缩放.

Last but not least, it is getting pretty important to start creating Winforms apps that are dpiAware so such a bug can never byte. You kick this off by declaring your app to be dpiAware so DPI virtualization is disabled. Plus whatever you need to do in your code to ensure the UI design scales properly.

这篇关于如何避免调整MDIParent表单的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆