首页 > 解决方案 > Flowlayoutpanel用鼠标滚动许多控件

问题描述

我有一个列表,其中填充了用户控件(约 300 个用户控件//每个 UC 都有一个图片框和 10 个标签)。我在 Flowlayoutpanel 中显示所有这些,但是当我向下或向上滚动时,它非常慢并且有点反应迟钝。我已经在使用 DoubleBuffered Flowlayoutpanel 和 SuspendLayout 和 ResumeLayout 的“技巧”。我正在尝试做的事情:我用鼠标向下滚动->当前两个用户控件不再出现在视图中时,删除它们->从底部的列表中添加两个新的用户控件。这也应该以相反的方式工作:用鼠标向上滚动 -> 当最后两个不再出现在视图中时,删除它们 -> 从顶部的列表中添加两个新的用户控件。 图片

我检查并尝试了我发现的所有内容,但它不起作用......我检查的一些链接:

 private void FlowLayoutPanel_MouseMove(object sender, MouseEventArgs e)
        {
            // move flowlayoutpanel with mouse
            if (e.Button != MouseButtons.Left)
                return;

            Point pointDifference = new Point(Cursor.Position.X + mouseDownPoint.X, Cursor.Position.Y - mouseDownPoint.Y);
            if ((mouseDownPoint.X == Cursor.Position.X) && (mouseDownPoint.Y == Cursor.Position.Y))
                return;

            Point currAutoScroll = FlowLayoutPanel.AutoScrollPosition;
            FlowLayoutPanel.AutoScrollPosition = new Point(Math.Abs(currAutoScroll.X) - pointDifference.X, Math.Abs(currAutoScroll.Y) - pointDifference.Y);
            mouseDownPoint = Cursor.Position;

            
            //
            Point locationOnForm = UClist[0].FindForm().PointToClient(
            UClist[0].Parent.PointToScreen(new Point(UClist[0].Location.X,UClist[0].Location.Y+300)));
            if (locationOnForm.Y < 190)
            {
                FlowLayoutPanel.SuspendLayout();
                FlowLayoutPanel.Controls.Clear();
                FlowLayoutPanel.Controls.AddRange(UClist.Skip(2).Take(2).ToArray());
                FlowLayoutPanel.ResumeLayout();
            }   
        }

我应该怎么做?

编辑 这就是我所说的 图片

标签: c#winformsflowlayoutpanel

解决方案


推荐阅读