如何确定VB.NET 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更改时,您都可以引发一个新事件;或者,如果仅因为VScroll现在可见而显示HScroll,则可以编写代码来“修复”控件.

我只想调用一个函数,并在滚动条可见的情况下使它返回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 ListView是否向用户显示垂直滚动条 - 代码日志