在 FlowLayoutPanel 滚动期间,背景扭曲 + 闪烁 [英] During FlowLayoutPanel scrolling, background distorts + flickers

查看:31
本文介绍了在 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.

有什么建议吗?

推荐答案

是的,那行不通.这是一个稍微改进它的类:

Yeah, that doesn't work. Here's a class that improves it somewhat:

using System;
using System.Windows.Forms;

class MyFlowLayoutPanel : FlowLayoutPanel {
    public MyFlowLayoutPanel() {
        this.DoubleBuffered = true;
    }
    protected override void OnScroll(ScrollEventArgs se) {
        this.Invalidate();
        base.OnScroll(se);
    }
}

编译并将其从工具箱顶部拖放到您的表单上.然而,它无法解决根本问题,即拖动时显示窗口内容"选项.这是一个系统选项,它将在更高版本的 Windows 中启用.当它打开时,Windows 本身会滚动面板的内容,然后要求应用程序绘制滚动显示的部分.OnScroll 方法会覆盖它,确保重新绘制整个窗口以保持背景图像就位.最终结果并不漂亮,你会看到图像在做pogo",滚动时上下跳跃.

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.

唯一的解决方法是关闭系统选项.这不是一个实际的修复,用户喜欢这个选项,它会影响每个程序,而不仅仅是你的程序.如果您不能忍受 pogo,那么您将不得不放弃透明度.

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.

这篇关于在 FlowLayoutPanel 滚动期间,背景扭曲 + 闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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