Home > C# Snippets > C#: WinForms – How to check if control scrollbars are (not)visible

C#: WinForms – How to check if control scrollbars are (not)visible

17:14

Marek Śliwiński Leave a comment Print This Post  (444) Go to comments
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);

internal static bool IsVerticalScrollBarVisible(Control ctrl)
{
    if (!ctrl.IsHandleCreated)
        return false;

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

internal static bool IsHorizontalScrollBarVisible(Control ctrl)
{
    if (!ctrl.IsHandleCreated)
        return false;

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

Usage example:

if (IsVerticalScrollBarVisible(ListView1))
DoSomething;
Share and Enjoy:
  • DotNetKicks
  • Digg
  • del.icio.us
  • Wikio IT
  • Google Bookmarks
  • Facebook
  • Print
Categories: C# Snippets Tags:
  1. No comments yet.
  1. No trackbacks yet.

Subscribe without commenting