c# - Flowlayoutpanel用鼠标滚动许多控件
问题描述
我有一个列表,其中填充了用户控件(约 300 个用户控件//每个 UC 都有一个图片框和 10 个标签)。我在 Flowlayoutpanel 中显示所有这些,但是当我向下或向上滚动时,它非常慢并且有点反应迟钝。我已经在使用 DoubleBuffered Flowlayoutpanel 和 SuspendLayout 和 ResumeLayout 的“技巧”。我正在尝试做的事情:我用鼠标向下滚动->当前两个用户控件不再出现在视图中时,删除它们->从底部的列表中添加两个新的用户控件。这也应该以相反的方式工作:用鼠标向上滚动 -> 当最后两个不再出现在视图中时,删除它们 -> 从顶部的列表中添加两个新的用户控件。 图片
我检查并尝试了我发现的所有内容,但它不起作用......我检查的一些链接:
- 带有很多控件的假滚动容器
- https://social.msdn.microsoft.com/Forums/en-US/bc881e4d-6770-44f0-85ce-51456920f938/adding-4000-child-controls-to-flowlayoutpanel-freezez-the-scrolling?forum=winforms
- 使用大量控件填充 FlowLayoutPanel 并按需绘制缩略图
- 如何在 FlowLayoutPanel 控件中实现分页效果?
- Winforms:具有数千个用户控件的可滚动 FlowLayoutPanel - 如何防止内存泄漏并以正确的方式处理对象?
- https://www.dreamincode.net/forums/topic/381141-flowlayoutpanel-paging-effect/
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();
}
}
我应该怎么做?
解决方案
推荐阅读
- php - Laravel phpUnit
- ios - swift didSelectAtIndexPath 没有被触发
- android - mvp中的presenter和mvvm中的view-model有什么区别
- c# - 在实体框架中连续删除和添加实体时出现异常
- python - PyQt5 中的 QObject、pyqtSignal
- python - Tensorflow - 在交互模式下使用估算器
- firebase - 后端模块中的 Firebase 管理员触发“所有 Firebase 库必须高于或低于 14.0.0
- javascript - 如何在不删除 JS 中的前一个的情况下向数组添加输入?
- python - TypeError:“int”类型的对象没有 len()?
- javascript - 只允许名字和姓氏中间有空格