这是 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