【问题标题】:Flickering and mess up flowLayoutPanel items while scrolling in winform C#在winform C#中滚动时闪烁并弄乱flowLayoutPanel项目
【发布时间】:2020-03-31 17:13:47
【问题描述】:

我有一个 flowLayoutPanel 有一些项目 .. 这些项目是我创建的自定义用户控件。 当我 scorll 时,这些项目会闪烁。

所以我创建了自定义 FLP 并将这段代码放入它的构造函数中:

this.SetStyle(
        ControlStyles.AllPaintingInWmPaint |
        ControlStyles.UserPaint |
        ControlStyles.DoubleBuffer, true);

但它仍然闪烁..然后我经过一番搜索找到了这段代码并添加了它:

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;
            return cp;
        }
    }

闪烁问题已解决..但此代码在滚动面板中导致一些性能问题..它变慢并且用户体验不佳:(

谁能帮忙解决这个问题??

【问题讨论】:

  • UserControl不应该有DoubleBuffer吗?
  • 它有..但没有做任何事情:)
  • 闪烁的是什么?用户控件?更好地记录这一点。

标签: c# winforms flicker tablelayoutpanel flowlayoutpanel


【解决方案1】:

你也可以试试这种风格:

this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

如果这还不够,您可以使用以下方法手动停止和恢复表单或控制绘图:

[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = 
CharSet.Ansi, SetLastError = true)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

private const int WM_SETREDRAW = 0xB;

public static void SuspendDrawing(Control target)
{
    if (target != null && !target.IsDisposed)
        SendMessage(target.Handle, WM_SETREDRAW, 0, 0);
}

public static void ResumeDrawing(Control target, bool redraw)
{
    if (target != null && !target.IsDisposed)
    {
        SendMessage(target.Handle, WM_SETREDRAW, 1, 0);

        if (redraw)
            target.Refresh();
    }
}

【讨论】:

    猜你喜欢
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 2021-05-11
    • 2018-06-20
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多