在 FlowLayoutPanel 滚动期间,背景会扭曲闪烁
我有一个有背景的 Windows 窗体应用程序。在其中,我有一个具有透明背景的 flowlayoutpanel。当我滚动时,会发生以下情况:
我还看到一些闪烁。双缓冲业务我都试过了,还是不行。
有什么建议吗?
I have a windows form application that has a background. Within it, I have a flowlayoutpanel with a transparent background. When I scroll, the following happens:
I also see some flickering. I've tried all the doublebuffered business, and it doesn't work.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这对我有用。
this is what worked for me.
是的,那行不通。这里有一个类对其进行了一些改进:
编译并将其从工具箱顶部拖放到表单上。然而,它无法解决根本问题,即“拖动时显示窗口内容”选项。这是一个系统选项,它将在更高版本的 Windows 中打开。当它打开时,Windows 本身会滚动面板的内容,然后要求应用程序绘制滚动显示的部分。 OnScroll 方法会重写该方法,确保重新绘制整个窗口以将背景图像保持在适当的位置。最终结果并不漂亮,您会看到图像在滚动时上下跳跃。
解决此问题的唯一方法是关闭系统选项。这不是一个实际的解决方案,用户喜欢这个选项,它会影响每个程序,而不仅仅是你的程序。如果您无法忍受 pogo,那么您将不得不放弃透明度。
Yeah, that doesn't work. Here's a class that improves it somewhat:
Compile and drop it from the top of the toolbox onto your form. It however cannot fix the fundamental problem, the "Show window content while dragging" option. That's a system option, it will be turned on for later versions of Windows. When it is on, Windows itselfs scrolls the content of the panel, then asks the app to draw the part that was revealed by the scroll. The OnScroll method overrides that, ensuring that the entire window is repainted to keep the background image in place. The end-result is not pretty, you'll see the image doing the "pogo", jumping up and down while scrolling.
The only fix for this is turning the system option off. That's not a practical fix, users like the option and it affects every program, not just yours. If you can't live with the pogo then you'll have to give up on the transparency.
我很高兴地报告 Hans 和整个互联网(只需学习 WPF....pfffft)在这里是错误的。
问题出在 WM_HSCROLL 和 WM_VSCROLL 事件中。通过一些试验和错误,我发现,如果我拖动滚动条足够快,我就能够将背景的幽灵副本移动到实际背景上,而实际背景是按照我想要的方式固定的。因此,无论可滚动控件内发生什么,Windows都能够跟上,并且一些不同步的重绘是导致剪切的原因。
那么如何解决这个问题呢?
将可滚动控件设置为 DoubleBuffered。
捕获 WM_HSCROLL/WM_VSCROLL 消息。无效。将“do_not_paint”标志设置为 true。调用base.WndProc()。将“do_not_paint”标志设置为 false。更新。
捕获 WM_PAINT 和相关消息。仅当“do_not_paint”标志为 false 时才调用 base.WndProc()。
这样做的作用是允许可滚动控件执行它需要执行的任何布局计算和滚动条重新定位,但不允许它重绘任何会触发剪切效果的内容。
I am very pleased to report that Hans, and the internet at large (just learn WPF....pfffft), is wrong here.
The problem is in the WM_HSCROLL and WM_VSCROLL events. Through some trial and error, I found that, if I dragged the scroll bar fast enough, I was able to move a ghost copy of my background over the actual background which was fxied how I wanted it. So whatever is happening inside the scrollable control, Windows is able to keep up and some out of sync redraw is what's causing the shearing.
So how do you solve this problem?
Set your scrollable control to DoubleBuffered.
Catch the WM_HSCROLL/WM_VSCROLL messages. Invalidate. Set the "do_not_paint" flag to true. Call the base.WndProc(). Set the "do_not_paint" flag to false. Update.
Catch the WM_PAINT and related messages. Only call base.WndProc() if the "do_not_paint" flag is false.
What this does is allow the scrollable control to do whatever layout calculations and scrollbar repositioning it needs to do but doesn't let it redraw anything that would trigger the shearing effect.
有点晚了……但是如果你搞乱了 Color.Transparent,就会发生这种情况。检查您的 FlowLayoutPanel 是否具有透明背景。如果是这样,请尝试改变这一点。
It´s a little bit late ... but this things happen if you mess with Color.Transparent. Check if your FlowLayoutPanel has Transparent Background. If so, try to change that.
我将 Application.DoEvents() 添加到 FlowPanel amd 的 Scroll 事件中,从而停止了我所获得的 FlowPanel 子控件的模糊。
I added Application.DoEvents() to the Scroll event of the FlowPanel amd that stopped the blurring of the FlowPanel child controls that I was getting.
试试这个
使用扩展窗口样式
try this
using Extended Window Styles