vb.net - 如何确定 VB.NET ListView 是否向用户显示垂直滚动条

标签 vb.net listview scrollbar visibility

我觉得这应该很简单,但我似乎无法找到如何做到这一点。

我有一个 ListView 控件,我只想确定是否向用户显示垂直滚动条。

我尝试了以下链接中的解决方案:

http://www.pcreview.co.uk/forums/detect-presence-listview-scrollbar-t1321101.html

http://support.microsoft.com/KB/299686

我没有任何运气。我正在使用 VB.NET

如果有人有任何想法,我将不胜感激。

最佳答案

这是 MSDN 答案的 NET 更新(如果你看,它与 VB6 相关):

'Pinvokes - these are usually Shared methods in a 
' Win32NativeMethods class you accumulate 
Private Const GWL_STYLE As Integer = -16
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000

<DllImport("user32.dll", SetLastError:=True)> _
private Shared Function GetWindowLong(ByVal hWnd As IntPtr, 
                       ByVal nIndex As Integer) As Integer
End Function

' sometimes you use wrappers since many, many, many things could call
' SendMessage and so that your code doesnt need to know all the MSG params
Friend Shared Function IsVScrollVisible(ByVal ctl As Control) As Boolean
    Dim wndStyle As Integer = GetWindowLong(ctl.Handle, GWL_STYLE)
    Return ((wndStyle And WS_VSCROLL) <> 0)

End Function

' to be complete:
Friend Shared Function IsHScrollVisible(ByVal ctl As Control) As Boolean
    Dim wndStyle As Integer = GetWindowLong(ctl.Handle, GWL_STYLE)
    Return ((wndStyle And WS_HSCROLL) <> 0)

End Function

在其他地方,订阅 ClientSizeChanged 事件:

Private VScrollVis As Boolean = False
Private Sub lv_ClientSizeChanged(sender As Object, e As EventArgs) 
               Handles myListView.ClientSizeChanged

    VScrollVis = IsVScrollVisible(Me)

    MyBase.OnClientSizeChanged(e)
End Sub

你没有说明你想做什么。您可以在 VScrollVis 更改时引发新事件,或者如果 HScroll 出现只是因为 VScroll 现在可见,您可以编写代码来“修复”控件。


我只是想调用一个函数并在滚动条可见时让它返回 true

' expose PInvoke if needed, convert to non-Shared
Public Function IsVerticalScrollVisible(ctl As Control)
   Return IsVScrollVisible(ctl)
End Function

Public Function IsHorizontalScrollVisible(ctl As Control)
   Return IsHScrollVisible(ctl)
End Function

关于vb.net - 如何确定 VB.NET ListView 是否向用户显示垂直滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24494406/

相关文章:

vb.net - VB - 这种有问题的做法会对性能产生什么后果?

android - Facebook 时间线,如 ListView

SQL 注入(inject)验证文本框

listview - 在 JavaFX 中更新 ListView 时出现 IndexOutOfBoundsException

android - 更改自定义 ListView 中的 TextView 值

html - 溢出 :scroll doesn't fill div/changes div size

用于桌面浏览器和 iOS & Android 的 JQuery 滚动条组件

java - SWING 禁用或隐藏滚动条,但启用滚轮?

javascript - 从javascript调用.ascx的vb.net函数,该函数也在.ascx中

vb.net - 在 Visual Basic 中四舍五入一个数字