C#判断Winform控件是否出现滚动条

参考代码

private const int WS_HSCROLL = 0x100000;
private const int WS_VSCROLL = 0x200000;
private const int GWL_STYLE = (-16);

[System.Runtime.InteropServices.DllImport("user32",CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hwnd, int nIndex);

/// 
/// 判断是否出现垂直滚动条
/// 
/// 待测控件
/// 出现垂直滚动条返回true,否则为false
private bool IsVerticalScrollBarVisible(Control ctrl)
{
    if (!ctrl.IsHandleCreated)
        return false;

    return (GetWindowLong(ctrl.Handle, GWL_STYLE) & WS_VSCROLL) != 0;
}

/// 
/// 判断是否出现水平滚动条
/// 
/// 待测控件
/// 出现水平滚动条返回true,否则为false
private  bool IsHorizontalScrollBarVisible(Control ctrl)
{
    if (!ctrl.IsHandleCreated)
        return false;
    return (GetWindowLong(ctrl.Handle, GWL_STYLE) & WS_HSCROLL) != 0;
}

你可能感兴趣的:(C#判断Winform控件是否出现滚动条)