创建ListView的滚动条出现了事件 [英] Create ListView ScrollBar Appeared Event

查看:113
本文介绍了创建ListView的滚动条出现了事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要的VScrollBar出现时创建一个事件一个ListView。我actully不想水平滚动条,并且只要VScrollbar看来我要调整列宽,使其适合窗口。我已经可以检查一个滚动条的可见性,但我不知道什么时候出现滚动条这是引发事件的名称。
这里是我的code:

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

和是这样的:

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

有人请帮助我!

推荐答案

ClientSizeChanged事件会火,但得到它的工作正确的,我们必须添加的BeginUpdate() EndUpdate() ..

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

这code做的一切:

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

这篇关于创建ListView的滚动条出现了事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆