【问题标题】:How to pass C# ListView scroll to parent container如何将 C# ListView 滚动传递给父容器
【发布时间】:2018-04-18 08:48:25
【问题描述】:

在我的 C# Windows 窗体应用程序中,我有一个包含 System.Windows.Forms.TabPage 的表单,其中包含多个 System.Windows.Forms.ListViews。 TabPage 有一个垂直滚动条。

在此 TabPage 中滚动时,当鼠标悬停在其中一个 ListView 上时,滚动停止。

当鼠标悬停在其中一个 ListView 上时,解决此问题并允许继续滚动的最佳方法是什么?

【问题讨论】:

    标签: c# winforms listview scroll tabpage


    【解决方案1】:

    搜索了一下,这是我的解决方案:

    我使用以下代码创建了一个新控件:

    using System;
    using System.Windows.Forms;
    
    namespace MyApplication.Controls
    {
        public class ScrollableListView : ListView
        {
            [System.Runtime.InteropServices.DllImport("User32.dll")]
            public static extern IntPtr PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
    
            protected override void WndProc(ref Message m)
            {
                const int WM_MOUSEWHEEL = 0x020A;
                switch (m.Msg)
                {
                    case WM_MOUSEWHEEL:
                        if (m.HWnd == Handle)
                        {
                            if (Parent is TabPage)
                                PostMessage((Parent as TabPage).Handle, m.Msg, m.WParam, m.LParam);
                        }
                        break;
                    default:
                        base.WndProc(ref m);
                        break;
                }
            }
        }
    }
    

    当在该控件上使用鼠标滚轮时,如果父控件是System.Windows.Forms.TabPage,则该事件将被发送到父控件。

    【讨论】:

      猜你喜欢
      • 2011-09-11
      • 1970-01-01
      • 2014-08-02
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多