调整窗口会导致黑条 [英] Resizing window causes black strips

查看:205
本文介绍了调整窗口会导致黑条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形式,这在构造函数设置这些样式:

I have a form, which sets these styles in constructor:

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

和我画一些长方形的油漆事件。有窗体上没有控件。 Hovewer,当我调整的形式,有黑条右边的表格和底部。有什么办法来摆脱他们?我用尽了一切,听 WM_ERASEBKGND 的WndProc ,在 WM_PAINT手动绘制表格,实现自定义的双缓冲,等有什么事我可以尝试?

And I draw some rectangles in Paint event. There are no controls on the form. Hovewer, when I resize the form, there are black strips at right and bottom of the form. Is there any way to get rid of them? I've tried everything, listening for WM_ERASEBKGND in WndProc, manually drawing the form on WM_PAINT, implementing custom double buffer, etc. Is there anything else I could try?

我发现这一点: <一href="https://connect.microsoft.com/VisualStudio/feedback/details/522441/custom-resizing-of-system-windows-window-flickers" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/522441/custom-resizing-of-system-windows-window-flickers 它看起来是DWM的错误,但我只是希望我可以做一些变通办法。

I've found this: https://connect.microsoft.com/VisualStudio/feedback/details/522441/custom-resizing-of-system-windows-window-flickers and it looks like it is a bug in DWM, but I just hope I can do some workaround.

请注意,我必须使用双缓冲,因为我想提请pretty的强烈图形presentation在油漆事件。我开发C#.net 2.0,Win7的。

Please note that I must use double buffering, since I want to draw pretty intense graphic presentation in the Paint event. I develop in C# .NET 2.0, Win7.

我已经通过自己实现调整大小功能,成功地摆脱了大部分的黑色条纹。 Hovewer仍然有一些小故障。有没有办法做到调整油漆运行一次?这里是一个伪$ C $什么,我需要做ç

I've managed to get rid of most of the black stripes by implementing the resize functionality by myself. Hovewer there are still some minor glitches. Is there any way to do resize and paint operation at once? Here is a pseudo-code of what I need to do:

IntPtr hDC;
var size = new Size(250, 200);
IntPtr handle = API.PaintAndResizeBegin(this.Handle /* Form.Handle */,
                                        size.Width, size.Height, out hDC);
using (var g = Graphics.FromHdc(hDC)) {
    this.backBuffer.Render(g, size);
}
API.PaintAndResizeCommit(handle);

有没有什么办法来实现上述code?

Is there any way to implement the above code?

第二种解决方案可以是背缓冲器整体的形式,包括非客户区。但如何做到这一点?我不想再刷非客户区由我自己,因为我想继续在Vista / 7的漂亮的Aero效果。任何帮助会深深AP preciated。

The second solution could be to back-buffer whole form, including non-client area. But how to do that? I don't want to paint the non-client area by myself, as I want to keep the nice aero effect on Vista/7. Any help will be deeply appreciated.

它看起来像这个问题是无法解决的,因为它是在Windows全方位present,在每个应用程序。我们只是希望,MS将在Mac OS X中的一些灵感,并会提供适当的API在新的Windows。

It looks like this problem is unsolvable, since it is omnipresent on Windows, in every application. We can just hope that MS will take some inspiration in Mac OS X and will provide appropriate APIs in new Windows.

推荐答案

我发现它可以画,并在同一时间调整窗口功能 - 的 UpdateLayeredWindow

I've found the function which can paint and resize window at the same time - UpdateLayeredWindow.

因此​​,现在应该是可以创建可调整大小的窗口,没有任何带而被调整。但是,你需要绘制窗口内容自己,所以这是一个有点不方便。但我认为,使用 WPF UpdateLayeredWindow ,不应该有任何问题。

So now it should be possible to create resizable windows, which do not have any strips while being resized. However, you need to paint the window content yourself, so it is a little inconvenient. But I think that using WPF and UpdateLayeredWindow, there shouldn't be any problem.

中发现的问题。 :-)使用 UpdateLayeredWindow ,你必须自己绘制窗口的边框。因此,使用,如果你想画标准的窗口 UpdateLayeredWindow 在WIN7漂亮的玻璃效果,你搞砸了。

Found problems. :-) When using UpdateLayeredWindow, you must paint the window's border yourself. So, if you want standard window painted using UpdateLayeredWindow with nice glass effect in win7, you are screwed.

在<一个href="https://connect.microsoft.com/VisualStudio/feedback/details/522441/custom-resizing-of-system-windows-window-flickers?wa=wsignin1.0"相对=nofollow> Microsft连接甚至一个线程关于这个问题,在微软说,它是设计中的错误,并且如果它被固定,那么很可能在Win8中或一些较新的系统。所以没有太多我们可以做这件事。

On Microsft Connect is even a thread about this problem, where Microsoft says it is a bug by design, and if it ever gets fixed, then probably in Win8 or some newer system. So there isn't much we could do about this.

这篇关于调整窗口会导致黑条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆