0

I created a simple single window WinForms app in VS2017 with a completely empty form. I added a manifest file to the application and uncommented the section on DPI awareness to make the application DPI aware. Now when I run the application and resize the window by dragging the right or bottom there are black lines drawn in the window. They go away when the window is minimized and maximized again.

enter image description here

If you look closely at the image you can see that the content area of the window (grey) covers up the border (blue) on the left and bottom edges. Seems related.

Here is the manifest:

<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
  </application>
</assembly>

Other than the manifest change, the rest of the application is what was generated by new WinForms application in VS2017 with no additions. The project targets .NET framework 4.6. I'm running on Windows 10 with scaling at 100%.

The reason I need the application to be dpi aware is to solve the issue with the CommonFileDialog described here: CommonOpenFileDialog cause Windows Form to shrink

Josh
  • 1,277
  • 12
  • 21
  • 2
    Set resizeredraw to true its a property in your form. Also set double buffer as well. – jgetner Jan 26 '18 at 04:14
  • That fixed the black lines on resize. The blue border is still covered up but I can live with that. You should make this the answer and I will accept it. – Josh Jan 26 '18 at 13:27
  • To get the border to show up on the right side you have minus the width by 1 as the blue line is getting pushed outside of the frame. Granted i have never drawn a border around a form with a caption still active. – jgetner Jan 26 '18 at 13:45
  • e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 0, 0, this.ClientSize.Width - 1, this.ClientSize.Height - 1); – jgetner Jan 26 '18 at 13:51

0 Answers0