【问题标题】:Scrolling in a flowlayoutpanel while dragging?拖动时在flowlayoutpanel中滚动?
【发布时间】:2012-08-31 16:10:24
【问题描述】:

我有一个 Windows 窗体应用程序,它使用 FlowLayoutPanel 控件来显示动态构建的图片框。我已经启用了拖放效果,因为他们可能想要重新排序它们,这仅适用于几个图片框(现在屏幕显示大约 6 个)但如果有更多你尝试在控件下方拖动一个项目它不会滚动,因此您不能将当前在屏幕上的图像(例如图像 4)放到可见图像下方的图像(例如图像 13)。

我看过几篇应该使用 ScrollControllIntoViewMethod 的帖子,我在几个地方尝试过都不成功。

谢谢!

【问题讨论】:

标签: c# .net winforms scroll flowlayoutpanel


【解决方案1】:

这就是我最终要做的。

在 DragLeave 事件上创建事件
获取控件的位置
计算控件的高度以获得下边界。
检查鼠标位置,如果超出界限,将垂直滚动(或水平滚动)更改为常量中的值..

private void thumbFlow_DragLeave(object sender, EventArgs e)
{
    int BegY_ThumbFlow = this.thumbFlow.FindForm().PointToClient(this.thumbFlow.Parent.PointToScreen(this.thumbFlow.Location)).Y;
    int thumbFlowBound_Y = this.thumbFlow.Height + BegY_ThumbFlow;
    int mouseY = this.thumbFlow.FindForm().PointToClient(MousePosition).Y;

    while (mouseY >= thumbFlowBound_Y)
    {
        thumbFlow.VerticalScroll.Value = thumbFlow.VerticalScroll.Value + DRAG_DROP_SCROLL_AMT;
        mouseY = thumbFlow.FindForm().PointToClient(MousePosition).Y;
        thumbFlow.Refresh();
    }

    while (mouseY <= BegY_ThumbFlow)
    {
        thumbFlow.VerticalScroll.Value = thumbFlow.VerticalScroll.Value - DRAG_DROP_SCROLL_AMT;
        mouseY = thumbFlow.FindForm().PointToClient(MousePosition).Y;
        thumbFlow.Refresh();
    }
}

希望这对其他人有所帮助。

【讨论】:

    猜你喜欢
    • 2011-01-15
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多