使用DoubleBuffering和FormBorderStyle.None在Windows10上重画问题 [英] Redraw issue on Windows10 with DoubleBuffering and FormBorderStyle.None
问题描述
我有一个Windows Forms项目问题,我只能在Windows 10
机器上重现该问题(在Windows 7上确实可以工作).我认为我可以隔离问题的根源,即,如果我打开双缓冲并将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):
,所以它看起来应该像:
and so it should looks like:
要重现该问题,只需将几个控件放在窗体上(可能数量也很重要),通过覆盖CreateParams
,FormBorderStyle=None
启用双重缓冲(使用其他边框样式即可!) .
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!).
后面的代码:
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窗体;))?
有什么想法吗?
双缓冲,没有边界必须是.
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.
更新:我有Win 10专业版:1703;内部版本15063.1155.
Update2:在Win 10 Pro版本上进行测试:1709;内部版本16299.492-同样的问题.
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:在Win 10 Home Version:1803上进行测试-更好的方法(我需要进行几分钟的测试才能重现它),但是仍然出现问题.该测试是在另一台装有另一张图形卡的计算机上完成的.
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.
解决方法:
恐怕我必须采用这种方法作为解决方法 A:在Windows窗体中删除标题栏并设置FormBorderStyle
例如FixedToolWindow
.
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
.
推荐答案
对我来说,这看起来像是操作系统中的错误,但我发现如何在不放弃DoubleBuffering
和FormBorderStyle=None
的情况下使其工作.
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
.
如果窗口样式将扩展
cp.ExStyle |= 0x00080000; // Turn on WS_EX_LAYERED
然后一切正常.
这篇关于使用DoubleBuffering和FormBorderStyle.None在Windows10上重画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!