简体   繁体   中英

How to get height of horizontal scrollbar in a ListView

Can anyone tell me how can I get the height of horizontal scrollbar in ListView in C#? is it the same as the standard Horizontal scrollbar, if so is there any windows function that return that? basically I'm using ListView with OwnerDraw and want to know exactly how big is my client area which excludes ColumnHeader area and HorizontalScrollbar area.

Thanks

Control.ClientRectangle excludes scrollbars and borders.

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

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

On .Net CF, where SystemInformation.HorizontalScrollBarHeight and SystemInformation.VerticalScrollBarWidth don't exist, some P/Invoke is required:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM