2

I have an issue with a Windows Forms project, which I can reproduce only on Windows 10 machine (on Windows 7 it does work). I think that I could isolate the source of issue, namely, if I switch double buffering on and set FormBorderStyle to None, then if I resize the form e.g. in an event handler, the parts of background and some controls being not redrawn. It is also so, that sometimes it works(one time from five).

Not redrawn it looks so(often a bit different):

enter image description here

and so it should looks like:

enter image description here

To reproduce the issue, just put a couple of controls to the form(may be amount can be also important), switch double buffering on via overriding of CreateParams, FormBorderStyle=None (with another border style it works!).

Code behind:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
            return cp;
        }
    }

    private bool small = true;
    private void button1_Click(object sender, EventArgs e)
    {
        //toggle the form's size
        Height = Height + 300*(small?-1:1);
        small = !small;
    }

    private void button5_Click(object sender, EventArgs e)
    {
        Close();
    }
}

Question:
Is it a known bug from MS(or may be intention, to get rid of windows forms ;) ) in Windows 10?
Any ideas?
Double buffering and no border must be.

Update: I have a Win 10 Pro Version: 1703; Build 15063.1155.
Update2: Test on Win 10 Pro Version: 1709; Build 16299.492 - the same issue.

Update3: Test on Win 10 Home Version: 1803 - much beter(I needed a couple of minutes of testing to reproduce it), but issue still appears. This test was done on another computer with another graphic card.

Workaround:
I'm afraid I have to go this way as workaround A: Remove the title bar in Windows Forms and set FormBorderStyle for instance to FixedToolWindow.

Rekshino
  • 6,954
  • 2
  • 19
  • 44
  • The *exact* Win10 build version matters a lot. They've been making sweeping changes in the legacy win32 code, especially early Insider releases were quite buggy this way. That hasn't stopped, RS4 previews are now being released. If you haven't updated recently or take Insider preview builds then you want to start there first. – Hans Passant Aug 13 '18 at 14:14
  • Can't reproduce the Issue on Windows 10 (Version 1803 Build 17134.165). Maybe this is related to your graphics card driver? – NineBerry Aug 13 '18 at 14:14
  • Win 10 Pro Version: 1703; Build 15063.1155 – Rekshino Aug 13 '18 at 14:15
  • @HansPassant Hmm.. :( Then I will try to find a possibility to test another build, e.g. as by NineBerry. – Rekshino Aug 13 '18 at 14:18
  • Yup, you are two versions behind. Keeping it updated is important. – Hans Passant Aug 13 '18 at 14:23
  • @HansPassant Say it to our sys. admins.. :( But may be in new version it's repaired :) – Rekshino Aug 13 '18 at 14:24
  • @NineBerry I will try to find it out, but first, I think, I will try to test newer Windows version, if I find one. – Rekshino Aug 13 '18 at 14:36
  • @HansPassant On Windows 10 Home(1803) the issue still appears. See Update3. – Rekshino Sep 11 '18 at 07:00
  • @NineBerry With another graphic card the issue still appears. See Update3. – Rekshino Sep 11 '18 at 07:01
  • Can you provide a complete project that reproduces the issue? – NineBerry Sep 11 '18 at 08:19
  • @NineBerry I have posted content of files in [chat](https://chat.stackoverflow.com/rooms/179797/room-for-rekshino-and-nineberry) – Rekshino Sep 11 '18 at 09:00
  • I can confirm that the issue happens with the demo project sometimes. Everything seems to be okay with the code. No idea, sorry. – NineBerry Sep 11 '18 at 10:31

1 Answers1

2

For me it looks like an error in OS, but I have found how to make it work without give up on DoubleBuffering and FormBorderStyle=None.

If window style will be extended by

cp.ExStyle |= 0x00080000;   // Turn on WS_EX_LAYERED

then all works as expected.

Rekshino
  • 6,954
  • 2
  • 19
  • 44