Is there a way to get the scrollbar height and width?

12,296

Solution 1

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

Namespace: System.Windows.Forms

Solution 2

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;
}
Share:
12,296
SwDevMan81
Author by

SwDevMan81

Twitter: @SwDevMan81 Mail: SwDevMan81 at Gmail Feel free to ping me for any questions you have. Job Title: Software Engineer Job Develop: Software for radar systems, Software GUI, real time embedded Current Languages: C#, C++, Java AS: Monroe Community College (Engineering Science) BS: University at Buffalo (Computer Science) MS: University at Buffalo (Computer Science & Engineering) MBA: Syracuse University (Business Analytics) Sites: Design Patterns Salt

Updated on June 08, 2022

Comments

  • SwDevMan81
    SwDevMan81 almost 2 years

    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.

  • Manatherin
    Manatherin about 13 years
    Thanks, saved me a lot of hassle