Menu

ScrollBar Visibility

Help
2023-02-07
2024-08-19
  • Jeff Gaines

    Jeff Gaines - 2023-02-07

    Is there a way to find out if the vertical ScrollBar is visible in an ObjectListView please?

     
  • Johnny J

    Johnny J - 2024-08-16

    Old question, but here is the answer in case somebody else needs it:

    [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
    public static extern IntPtr GetWindowLong32(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
    public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);

    private bool HasHorizontalScrollBar(ListView lv)
    {
    const int GWL_STYLE = -16;
    const int WS_HSCROLL = 0x00100000;

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

    }

    private bool HasVerticalScrollBar(ListView lv)
    {
    const int GWL_STYLE = -16;
    const int WS_VSCROLL = 0x00200000;

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

    }

    private int GetWindowLong(IntPtr hWnd, int nIndex)
    {
    if (IntPtr.Size == 4)
    return (int)GetWindowLong32(hWnd, nIndex);
    else
    return (int)(long)GetWindowLongPtr64(hWnd, nIndex);
    }

     
    • Jeff Gaines

      Jeff Gaines - 2024-08-19

      Many thanks, Johnny J, works a treat!

       

Log in to post a comment.