CommonOpenFileDialog cause Windows Form to shrink

2019-06-20 11:22发布

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 Windows API CodePack to get access to the CommonOpenFileDialog- all good there.

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:

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

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.

Code to open the form is:

CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.DefaultDirectory = selectedFolderTextBox.Text;
dialog.IsFolderPicker = true;

if (dialog.ShowDialog() != CommonFileDialogResult.Ok) return;

selectedFolderTextBox.Text = dialog.FileName;

1条回答
甜甜的少女心
2楼-- · 2019-06-20 11:38

Enable dpi-aware by adding app.manifest file, and uncomment this blocks.

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

This works for me on my Surface Pro 4(dpi scale 200%).

查看更多
登录 后发表回答