<small id='78t5p'></small><noframes id='78t5p'>

    1. <tfoot id='78t5p'></tfoot>
        <bdo id='78t5p'></bdo><ul id='78t5p'></ul>
    2. <i id='78t5p'><tr id='78t5p'><dt id='78t5p'><q id='78t5p'><span id='78t5p'><b id='78t5p'><form id='78t5p'><ins id='78t5p'></ins><ul id='78t5p'></ul><sub id='78t5p'></sub></form><legend id='78t5p'></legend><bdo id='78t5p'><pre id='78t5p'><center id='78t5p'></center></pre></bdo></b><th id='78t5p'></th></span></q></dt></tr></i><div id='78t5p'><tfoot id='78t5p'></tfoot><dl id='78t5p'><fieldset id='78t5p'></fieldset></dl></div>

      <legend id='78t5p'><style id='78t5p'><dir id='78t5p'><q id='78t5p'></q></dir></style></legend>

    3. CommonOpenFileDialog 导致 Windows 窗体缩小

      时间:2023-09-14
        <tbody id='x4zL8'></tbody>
        <bdo id='x4zL8'></bdo><ul id='x4zL8'></ul>
        • <i id='x4zL8'><tr id='x4zL8'><dt id='x4zL8'><q id='x4zL8'><span id='x4zL8'><b id='x4zL8'><form id='x4zL8'><ins id='x4zL8'></ins><ul id='x4zL8'></ul><sub id='x4zL8'></sub></form><legend id='x4zL8'></legend><bdo id='x4zL8'><pre id='x4zL8'><center id='x4zL8'></center></pre></bdo></b><th id='x4zL8'></th></span></q></dt></tr></i><div id='x4zL8'><tfoot id='x4zL8'></tfoot><dl id='x4zL8'><fieldset id='x4zL8'></fieldset></dl></div>
        • <legend id='x4zL8'><style id='x4zL8'><dir id='x4zL8'><q id='x4zL8'></q></dir></style></legend>
          <tfoot id='x4zL8'></tfoot>

                <small id='x4zL8'></small><noframes id='x4zL8'>

                本文介绍了CommonOpenFileDialog 导致 Windows 窗体缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一直在开发一个 Windows 窗体应用程序,最近添加了一个简单的设置页面,允许用户选择一个文件夹来存放输出.OpenFileDialog 丑陋且不好用,所以我在 WindowsAPICodePack 中添加了对 CommonOpenFileDialog 的访问 - 一切都很好.

                I've been working on a Windows Forms application, and have recently added a simple settings page that allows the user to select a folder for where the output goes. The OpenFileDialog is ugly and not nice to use, so I've added in the WindowsAPICodePack to get access to the CommonOpenFileDialog - all good there.

                当我打开 CommonOpenFileDialog 时,Windows 窗体应用程序会缩小到更小的尺寸,如附图所示.

                When I open the CommonOpenFileDialog, the Windows form application shrinks to a smaller size, as shown in the image attached.

                左边是正常程序,右边是打开对话框:

                On the left is the program normally, on the right is with the dialog open:

                我尝试过检查 Form 前后的大小,但没有改变,所以我遇到了一些问题.任何信息都会很有用,如果需要,我可以提供更多详细信息.

                I've tried checking the size of the Form before and after, that's not changing, so I'm hitting a bit of a brick wall. Any information would be useful, I can provide more details if needed.

                打开对话框的代码是:

                CommonOpenFileDialog dialog = new CommonOpenFileDialog();
                dialog.DefaultDirectory = selectedFolderTextBox.Text;
                dialog.IsFolderPicker = true;
                
                if (dialog.ShowDialog() != CommonFileDialogResult.Ok) return;
                
                selectedFolderTextBox.Text = dialog.FileName;
                

                推荐答案

                我在windows Settings->System窗体中更改Scale and layout时出现这个问题100% 到更高的值.这可能与高 DPI 和 DPI 缩放有关.

                This problem happens to me when I change the Scale and layout in windows Settings->System form 100% to a higher value. It probably has to do with high DPI and DPI scaling.

                我找到了几个解决方案:

                I found several solution:

                此解决方案仅适用于 .NET Framework 4.7 或更高版本.

                将此添加到 App.config 文件中.

                Add this to to App.config file.

                <System.Windows.Forms.ApplicationConfigurationSection>
                    <add key="DpiAwareness" value="PerMonitorV2" />
                </System.Windows.Forms.ApplicationConfigurationSection> 
                

                来源:配置您的高 DPI 支持的 Windows 窗体应用程序:

                在 app.config 文件中启用每个显示器的 DPI 感知.

                Enable per-monitor DPI awareness in the app.config file.

                Windows 窗体介绍了一个新的System.Windows.Forms.ApplicationConfigurationSection 元素到支持从 .NET 开始添加的新功能和自定义框架 4.7.利用支持高的新功能DPI,将以下内容添加到您的应用程序配置文件中.

                Windows Forms introduces a new System.Windows.Forms.ApplicationConfigurationSection element to support new features and customizations added starting with the .NET Framework 4.7. To take advantage of the new features that support high DPI, add the following to your application configuration file.

                <System.Windows.Forms.ApplicationConfigurationSection>
                    <add key="DpiAwareness" value="PerMonitorV2" />
                </System.Windows.Forms.ApplicationConfigurationSection> 
                

                重要

                在以前版本的 .NET Framework 中,您使用清单来添加高 DPI 支持.不再推荐这种方法,因为它覆盖 app.config 文件中定义的设置.

                In previous versions of the .NET Framework, you used the manifest to add high DPI support. This approach is no longer recommended, since it overrides settings defined on the app.config file.

                解决方案 2:使用 Ookii.Dialogs.WinForms NuGet 包

                使用 Ookii.Dialogs.WinForms NuGet 包.它不存在缩水问题.它有一个类似于 WindowsAPICodePack 的 CommonFileDialogVistaOpenFileDialog.它还有一个不错的文件夹浏览器 VistaFolderBrowserDialog,就像 CommonFileDialog 一样,IsFolderPicker 设置为 true.

                Solution 2: Use Ookii.Dialogs.WinForms NuGet package

                Use the Ookii.Dialogs.WinForms NuGet package. It doesn't have the shrinking problem. It has a VistaOpenFileDialog similar to the CommonFileDialog of WindowsAPICodePack. It also has a nice folder browser VistaFolderBrowserDialog like the CommonFileDialog with IsFolderPicker set to true.

                此解决方案需要单独手动更改每个应用程序 .exe 文件的兼容性设置,因此不是最佳解决方案.

                This solution requires to manually change the compatibility settings for each application .exe file individually, so it not the best solution.

                为此,您需要右键单击 .exe 文件,选择 属性->兼容性->更改高 DPI 设置并选中 覆盖高 DPI 缩放行为并选择其中一个选项(请参阅:如何在 Windows 10 中使用 DPI 缩放来修复模糊的旧应用)

                To do this you need to right-click on the .exe file, select Properties->Compatibility->Change high DPI settings and check Override high DPI scaling behavior and select one of the options (see: How to use DPI scaling in Windows 10 to fix blurry old apps)

                这篇关于CommonOpenFileDialog 导致 Windows 窗体缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:来自 WaterfallStep Dialog MS Bot 框架 v4 的自适应卡片响应 下一篇:SaveFileDialog 上的 DialogResult.OK 不起作用

                相关文章

                  <tfoot id='XraT1'></tfoot>
                    • <bdo id='XraT1'></bdo><ul id='XraT1'></ul>

                    <small id='XraT1'></small><noframes id='XraT1'>

                  1. <legend id='XraT1'><style id='XraT1'><dir id='XraT1'><q id='XraT1'></q></dir></style></legend>
                    <i id='XraT1'><tr id='XraT1'><dt id='XraT1'><q id='XraT1'><span id='XraT1'><b id='XraT1'><form id='XraT1'><ins id='XraT1'></ins><ul id='XraT1'></ul><sub id='XraT1'></sub></form><legend id='XraT1'></legend><bdo id='XraT1'><pre id='XraT1'><center id='XraT1'></center></pre></bdo></b><th id='XraT1'></th></span></q></dt></tr></i><div id='XraT1'><tfoot id='XraT1'></tfoot><dl id='XraT1'><fieldset id='XraT1'></fieldset></dl></div>