如何在ListView中获取水平滚动条的高度

时间:2009-07-24 16:00:58

标签: c#

有谁能告诉我如何在C#中获取ListView中水平滚动条的高度?它是否与标准水平滚动条相同,如果有的话,是否有任何窗口函数返回?基本上我正在使用ListView和OwnerDraw,并想知道我的客户区有多大,它排除了ColumnHeader区域和Horizo​​ntalScrollbar区域。

由于

3 个答案:

答案 0 :(得分:10)

答案 1 :(得分:2)

Control.ClientRectangle排除滚动条和边框。

    listView1.Scrollable = true;
    Console.WriteLine(listView1.ClientRectangle);
    Console.WriteLine(listView1.Size);
    listView1.Scrollable = false;

    Console.WriteLine(listView1.ClientRectangle);
    Console.WriteLine(listView1.Size);

答案 2 :(得分:0)

在.Net CF上,SystemInformation.HorizontalScrollBarHeightSystemInformation.VerticalScrollBarWidth不存在,需要一些P / Invoke:

public sealed class Native
{
    public static Int32 GetVerticalScrollbarWidth()
    {
        return GetSystemMetrics(SM_CXVSCROLL);
    }

    public Int32 GetHorizontalScrollbarHeight()
    {
        return GetSystemMetrics(SM_CYHSCROLL);
    }

    [DllImport("coredll.dll", SetLastError = true)]
    public static extern Int32 GetSystemMetrics(Int32 index);

    public const Int32
        SM_CXVSCROLL = 2,
        SM_CYHSCROLL = 3;
}
相关问题