使用 DoubleBuffering 和 FormBorderStyle.None 在 Windows10 上重绘问题

Redraw issue on Windows10 with DoubleBuffering and FormBorderStyle.None

我有一个 Windows Forms 项目的问题,我只能在 Windows 10 机器上重现它(在 Windows 7 上它确实有效)。我认为我可以隔离问题的根源,即,如果我打开双缓冲并将 FormBorderStyle 设置为 None,那么如果我调整表单的大小,例如在事件处理程序中,背景部分和某些控件未重绘。也是如此,有时它会起作用(五次一次)。

没有重新绘制它看起来如此(通常有点不同):

所以它应该看起来像:

要重现该问题,只需在表单中放置几个​​控件(可能数量也很重要),通过覆盖 CreateParamsFormBorderStyle=None(使用另一个边框样式有效!)。

后面的代码:

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();
    }
}

问题:
Windows 10 中的 MS 已知错误(或者可能是故意的,以摆脱 windows 形式 ;))?
有什么想法吗?
必须是双缓冲和无边框。

更新:我有一个Win 10专业版:1703;内部版本 15063.1155。
更新2:在Win 10专业版上测试:1709;构建 16299.492 - 同样的问题。

Update3: 在 Win 10 家庭版上测试:1803 - 好多了(我需要几分钟的测试来重现它),但问题仍然出现。此测试是在另一台计算机上使用另一张显卡进行的。

解决方法:
恐怕我必须采用这种方式作为解决方法 A: Remove the title bar in Windows Forms 并将 FormBorderStyle 例如设置为 FixedToolWindow.

对我来说,它看起来像是 OS 中的一个错误,但我已经找到了如何在不放弃 DoubleBufferingFormBorderStyle=None 的情况下使其工作。

如果 window 样式将扩展

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

然后一切正常。