创建ListView滚动条显示事件

本文关键字:事件 显示 滚动条 ListView 创建 | 更新日期: 2023-09-27 18:25:45

我有一个ListView,当VScrollBar出现时,我想在其中创建一个事件。我实际上不想要水平滚动条,每当出现VScrollbar时,我都想调整列的大小,使其适合窗口。我已经可以检查滚动条的可见性,但我不知道当滚动条出现时触发的事件的名称。这是我的代码:

    private const int WS_VSCROLL = 0x200000;
    private const int GWL_STYLE = -16;
    [DllImport("user32.dll")]
    public static extern int GetWindowLong(IntPtr hWnd, int Index);
    private static bool IsScrollbarVisible(IntPtr hWnd)
    {
        bool bVisible = false;
        int nMessage = WS_VSCROLL;
        int nStyle = GetWindowLong(hWnd, GWL_STYLE);
        bVisible = ((nStyle & nMessage) != 0);
        return bVisible;
    }

工作原理如下:

    if (IsScrollbarVisible(listview.Handle))
    {
          columnHeader1.Width = listview.ClientRectangle.Width - (columnHeader2.Width + columnHeader3.Width);
    }

有人请帮帮我!

创建ListView滚动条显示事件

ClientSizeChanged事件将触发,但要使其正常工作,我们必须添加BeginUpdate()EndUpdate()。。

这个代码做任何事情:

    private void listview_ClientSizeChanged(object sender, EventArgs e)
    {
        listview.BeginUpdate();
        if (IsScrollbarVisible(listview.Handle))
        {
            columnHeader1.Width = listview.ClientRectangle.Width - (columnHeader2.Width + columnHeader3.Width);
        }
        listview.EndUpdate();
    }