检查滚动条可见性

Clo*_*aky 5 c# listview visibility scrollbar winforms

有没有办法检查垂直滚动条在某个 ListView 对象上是否可见?

我有一个带有 listView 的 Windows 窗体,在调整大小事件中,我想捕获 listview 的垂直滚动条是否可见!

Aar*_*ver 3

如果这是 WPF,则此处存在一个示例,该示例位于解决方案的基础上挂钩到ListView.LayoutUpdated.

如果这是 WinForms,您可以使用 pinvoke 和GetWindowLong ...

  static public class WndInfo
  {
    [DllImport("user32.dll", SetLastError = true)]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    ...
    public static bool IsWindowTopMost(IntPtr Handle)
    {
      return (GetWindowLong(Handle, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
    }
    ...
  }
Run Code Online (Sandbox Code Playgroud)

VB 代码用于GetWindowLong检查 ScrollBar 是否存在,您可以将其移植到 C#。