Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...