问题描述
我有一个 Windows 窗体项目的问题,我只能在 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):
所以它应该看起来像:
要重现该问题,只需在表单上添加几个控件(可能数量也很重要),通过覆盖 CreateParams
、FormBorderStyle=None<来打开双缓冲/code> (它可以使用另一种边框样式!).
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 Pro 版本: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.
更新 3: 在 Win 10 家庭版上测试: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
为例.
推荐答案
对我来说这看起来像是操作系统中的一个错误,但我已经找到了如何在不放弃 DoubleBuffering
和 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
然后一切都按预期工作.
then all works as expected.
这篇关于使用 DoubleBuffering 和 FormBorderStyle.None 在 Windows10 上重绘问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!