Search code examples
c#winformsvisual-studiorenderingformborderstyle

Forms don't render properly in Visual Studio


I am using Visual Studio Community 2017, but the same problem appeared on older versions too. In almost every WinForm app in form_load I write this:

FormBorderStyle = FormBorderStyle.FixedSingle;
CenterToScreen();

Before any code, in form properties, I always set ShowIcon to false, and FormBorderStyle to None. But, always I experience the same problems:
1) Instead of nothing I see little Console Icon in top-left corner of window.
2) two stripes (I'd say 10-20 pixels wide) on right and bottom side of form's window don't render at all.
I need to minimize and open the window back to fix that. After minimizing Form is rendered fully. How can I fix this? This became really annoying.

Here is a screenshot:
Bad rendering


Solution

  • I found the solution. Don't write this commands in form_load void, but in constructor:

    public Form1()
    {
         InitializeComponent();
         FormBorderStyle = FormBorderStyle.FixedSingle;
         CenterToScreen();
    }
    

    And the Icon will hide properly :)