1. <legend id='2hAn9'><style id='2hAn9'><dir id='2hAn9'><q id='2hAn9'></q></dir></style></legend>

    <small id='2hAn9'></small><noframes id='2hAn9'>

    • <bdo id='2hAn9'></bdo><ul id='2hAn9'></ul>

  2. <tfoot id='2hAn9'></tfoot>
    <i id='2hAn9'><tr id='2hAn9'><dt id='2hAn9'><q id='2hAn9'><span id='2hAn9'><b id='2hAn9'><form id='2hAn9'><ins id='2hAn9'></ins><ul id='2hAn9'></ul><sub id='2hAn9'></sub></form><legend id='2hAn9'></legend><bdo id='2hAn9'><pre id='2hAn9'><center id='2hAn9'></center></pre></bdo></b><th id='2hAn9'></th></span></q></dt></tr></i><div id='2hAn9'><tfoot id='2hAn9'></tfoot><dl id='2hAn9'><fieldset id='2hAn9'></fieldset></dl></div>
    1. C#在ListView中实现拖拽时自动滚动&amp;掉落

      时间:2023-08-25
    2. <i id='muXdC'><tr id='muXdC'><dt id='muXdC'><q id='muXdC'><span id='muXdC'><b id='muXdC'><form id='muXdC'><ins id='muXdC'></ins><ul id='muXdC'></ul><sub id='muXdC'></sub></form><legend id='muXdC'></legend><bdo id='muXdC'><pre id='muXdC'><center id='muXdC'></center></pre></bdo></b><th id='muXdC'></th></span></q></dt></tr></i><div id='muXdC'><tfoot id='muXdC'></tfoot><dl id='muXdC'><fieldset id='muXdC'></fieldset></dl></div>
        <tfoot id='muXdC'></tfoot>
            <tbody id='muXdC'></tbody>

              <bdo id='muXdC'></bdo><ul id='muXdC'></ul>
              <legend id='muXdC'><style id='muXdC'><dir id='muXdC'><q id='muXdC'></q></dir></style></legend>

                <small id='muXdC'></small><noframes id='muXdC'>

                本文介绍了C#在ListView中实现拖拽时自动滚动&amp;掉落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如何在 Winforms ListView 中实现自动滚动(例如,当您靠近顶部或底部时,ListView 会滚动)?我在谷歌上四处搜寻,运气不佳.我不敢相信这不是开箱即用的!提前致谢戴夫

                How do I implement Auto-Scrolling (e.g. the ListView scrolls when you near the top or bottom) in a Winforms ListView? I've hunted around on google with little luck. I can't believe this doesn't work out of the box! Thanks in advance Dave

                推荐答案

                滚动可以通过 ListViewItem.EnsureVisible 方法.您需要确定您当前拖过的项目是否位于列表视图的可见边界,并且不是第一个/最后一个.

                Scrolling can be accomplished with the ListViewItem.EnsureVisible method. You need to determine if the item you are currently dragging over is at the visible boundary of the list view and is not the first/last.

                private static void RevealMoreItems(object sender, DragEventArgs e)
                {
                    var listView = (ListView)sender;
                
                    var point = listView.PointToClient(new Point(e.X, e.Y));
                    var item = listView.GetItemAt(point.X, point.Y);
                    if (item == null)
                        return;
                
                    var index = item.Index;
                    var maxIndex = listView.Items.Count;
                    var scrollZoneHeight = listView.Font.Height;
                
                    if (index > 0 && point.Y < scrollZoneHeight)
                    {
                        listView.Items[index - 1].EnsureVisible();
                    }
                    else if (index < maxIndex && point.Y > listView.Height - scrollZoneHeight)
                    {
                        listView.Items[index + 1].EnsureVisible();
                    }
                }
                

                然后将此方法连接到 DragOver 事件.

                Then wire this method to the DragOver event.

                targetListView.DragOver += RevealMoreItems;
                
                targetListView.DragOver += (sender, e) =>
                {
                    e.Effect = DragDropEffects.Move;
                };
                

                这篇关于C#在ListView中实现拖拽时自动滚动&amp;掉落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:C# 在 Canvas 中拖放图像 下一篇:在 C# Windows 窗体中的同一 ListView 控件中重新排序

                相关文章

                最新文章

              1. <legend id='1NNWI'><style id='1NNWI'><dir id='1NNWI'><q id='1NNWI'></q></dir></style></legend>
                  <bdo id='1NNWI'></bdo><ul id='1NNWI'></ul>

                  <small id='1NNWI'></small><noframes id='1NNWI'>

                1. <i id='1NNWI'><tr id='1NNWI'><dt id='1NNWI'><q id='1NNWI'><span id='1NNWI'><b id='1NNWI'><form id='1NNWI'><ins id='1NNWI'></ins><ul id='1NNWI'></ul><sub id='1NNWI'></sub></form><legend id='1NNWI'></legend><bdo id='1NNWI'><pre id='1NNWI'><center id='1NNWI'></center></pre></bdo></b><th id='1NNWI'></th></span></q></dt></tr></i><div id='1NNWI'><tfoot id='1NNWI'></tfoot><dl id='1NNWI'><fieldset id='1NNWI'></fieldset></dl></div>
                  <tfoot id='1NNWI'></tfoot>