Create ListView ScrollBar Appeared Event

江枫思渺然 提交于 2019-12-23 04:36:29

问题


I have a ListView in which i want to create an event when the VScrollBar appears. I actully dont want a horizontal scrollbar and whenever the VScrollbar appears i want to resize the columns so that it fits the window. I already can check for the visiblity of a scrollbar but i dont know the name of the event which is triggered when the ScrollBars appear. Here is my code :

    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;
    }

And Works Like this :

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

Someone Please Help Me!


回答1:


ClientSizeChanged Event will fire but to get it work correct we have to add BeginUpdate() and EndUpdate()..

This Code does everything :

    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();
    }


来源:https://stackoverflow.com/questions/9452060/create-listview-scrollbar-appeared-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!