10

I'm trying to get the height and width of the scrollbars that are displayed on a ListView. Is there an easy way to do this? I did some google'ing and it looks like it might be a system setting. I'm just not sure where to look.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184

2 Answers2

20

Yes, it is a system setting. Use SystemInformation.HorizontalScrollBarHeight and SystemInformation.VerticalScrollBarWidth.

Namespace: System.Windows.Forms

Venkat
  • 2,549
  • 2
  • 28
  • 61
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
7

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;
}
Johann Gerell
  • 24,991
  • 10
  • 72
  • 122