确定一个ListView是否已经显示它自己和DEFAULT VerticalScrollbar? [英] Determine whether a ListView has been displayed it's own and DEFAULT VerticalScrollbar?
问题描述
我要确定我的控制是否已经显示它的集成默认 VerticalScrollbar
,我备注默认部分事业的一切,我已经看到了对继承用户控件使用自定义VScrolls,但实际上我不是pretending乱用自定义VScrollbar只是为了确定一个值,表明它的pressence的解决方案里面的客户区。
I need to determine in my control whether it has been displayed it's integrated DEFAULT VerticalScrollbar
, I remark the DEFAULT part 'cause all the solutions that I've seen are for inherited user-controls that uses custom VScrolls, but really I'm not pretending to mess with a custom VScrollbar just to determine a value indicating its pressence inside the client area.
我已经试过这个建议的解决方案,但不与工作至少使用它ListView的默认滚动条,我的意思是控件集合始终是零甚至当VerticalScrollbar存在。
I've tried this suggested solution, but is not working at least with a Listview that uses it's default Scrollbars, I mean that the Controls collection always is Zero even when the VerticalScrollbar exists.
此外,我已经试过这个其他的解决办法,但似乎不没有工作列表视图'导致它不能识别一个ListView为 ScrollableControl
,太奇怪了。
Also I've tried this other solution, but seems that does not work for Listviews 'cause it can't recognize a ListView as an ScrollableControl
, so strange.
注意:我的列表视图的大小也不是一成不变的,我的意思是我指定锚属性,以便在ListView调整大小一起当窗体调整大小,然后我也觉得算术的一招式测量的所有列的宽度和等来确定滚动条的pressence也许不会是一个有效的方法(Ⅰ不知道是否可以)。
Note: The size of my Listview is not static, I mean I've specified the anchor property so the listview is resized together when the Form resizes then also I think that a trick of an arithmetic formula measuring the width of all the columns and etc. to determine the pressence of the Scrollbar maybe will not be an efficient way (I don't know if could be).
注意2::如果它的需要来确定这一点,我可以继承ListView控件,但正如我已经说过我preffer避免定制VSCROLL的用法,我不需要它,这将引发其他问题,我想prevent因为我没有经历过自定义滚动条的用法。
Note 2: I can inherit the ListView control if it's needed to determine this, but as I've said I preffer to avoid the usage of a custom VScroll, I don't need it and that will provoke other questions that I want to prevent 'cause I'm not experienced with the usage of custom scrollbars.
推荐答案
您可以在任何给定的时间检查,如果一个控件有一个 WS_VSCROLL
或 WS_HSCROLL
窗口样式通过调用 GetWindowLong 和/或 GetWindowLongPtr 。
You can at any given time check if a control has a WS_VSCROLL
or WS_HSCROLL
window style by invoking GetWindowLong and/or GetWindowLongPtr.
'Private Const WS_VSCROLL As Integer = &H200000
'Private Const WS_HSCROLL As Integer = &H100000
'Private Const GWL_STYLE As Integer = -16
<DllImport("user32.dll", EntryPoint:="GetWindowLong", CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowLong32(ByVal hWnd As HandleRef, ByVal nIndex As Integer) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="GetWindowLongPtr", CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowLong64(ByVal hWnd As HandleRef, ByVal nIndex As Integer) As IntPtr
End Function
Public Shared Function GetScrollbars(ctl As Control) As ScrollBars
If (ctl Is Nothing) Then Throw New ArgumentNullException("ctl")
Dim horizontal As Boolean = False
Dim vertical As Boolean = False
If (IntPtr.Size = 4) Then
Dim style As Integer = GetWindowLong32(New HandleRef(ctl, ctl.Handle), -16I).ToInt32()
horizontal = ((style And &H100000I) = &H100000I)
vertical = ((style And &H200000I) = &H200000I)
Else
Dim style As Long = GetWindowLong64(New HandleRef(ctl, ctl.Handle), -16I).ToInt64()
horizontal = ((style And &H100000L) = &H100000L)
vertical = ((style And &H200000L) = &H200000L)
End If
If (horizontal AndAlso vertical) Then
Return ScrollBars.Both
ElseIf (horizontal) Then
Return ScrollBars.Horizontal
ElseIf (vertical) Then
Return ScrollBars.Vertical
End If
Return ScrollBars.None
End Function
这篇关于确定一个ListView是否已经显示它自己和DEFAULT VerticalScrollbar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!