确定ListView是否已显示为它自己和DEFAULT VerticalScrollbar? [英] Determine whether a ListView has been displayed it's own and DEFAULT VerticalScrollbar?

查看:59
本文介绍了确定ListView是否已显示为它自己和DEFAULT VerticalScrollbar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定控件中是否已经集成了 DEFAULT VerticalScrollbar ,我将 DEFAULT 部分标记为我见过的解决方案是针对使用自定义VScrolls的继承用户控件的,但实际上我不假装与自定义VScrollbar只是为了确定一个指示其在客户区域内部压力的值.

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.

我已经尝试过此建议的解决方案,但至少不能与使用它的默认Scrollbars的Listview,我的意思是,即使VerticalScrollbar存在,Controls集合也始终为零.

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.

我也尝试过这另一种解决方案,但看来确实可以不适用于Listviews,因为它无法将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的大小不是静态的,我的意思是我指定了anchor属性,以便在Form调整大小时一起调整Listview的大小,然后我也认为这是一种算术技巧确定所有滚动条等的宽度的公式以确定滚动条的压力的方法可能不是一种有效的方法(我不知道是否可以).

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 控件,但正如我所说,我倾向于避免使用自定义 VScroll,我不需要它并且这会引发其他我要避免的问题,因为我对使用自定义滚动条没有经验.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆