Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

c# - Redraw issue on Windows10 with DoubleBuffering and FormBorderStyle.None

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...