有没有办法获得滚动条的高度和宽度?

SwD*_*n81 8 .net c# listview scrollbar

我正在尝试获取ListView上显示的滚动条的高度和宽度.是否有捷径可寻?我做了一些google'ing,看起来它可能是一个系统设置.我只是不确定在哪里看.

Han*_*ant 18

是的,这是一个系统设置.使用SystemInformation.Horizo​​ntalScrollBarHeightSystemInformation.VerticalScrollBarWidth.

命名空间:System.Windows.Forms


Joh*_*ell 6

在.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;
}
Run Code Online (Sandbox Code Playgroud)