Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

331
Visualizações
CommonOpenFileDialog cause Windows Form to shrink

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.

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 dialog is:

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

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

selectedFolderTextBox.Text = dialog.FileName;
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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:

Solution 1: Configuring Windows Forms for high DPI support

This solution is only for .NET Framework version 4.7 or higher.

Add this to to App.config file.

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

Source: Configuring your Windows Forms app for high DPI support:

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

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> 

Important

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.

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.

Solution 3: Override high DPI scaling behavior for the .exe file

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

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)

about 4 years ago · Santiago Trujillo Relatório

0

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%).

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda