gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:58:19 25 4
gpt4 key购买 nike

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

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com