1

Visual Basic 2010, .NET 3.5 有没有办法务实地确定 DataGridView 的水平滚动条是活动的还是可见的?我需要移动一些关于 DGV 的水平滚动条何时出现的项目。

4

4 回答 4

5

尝试这个:

dgvYourDataGridView.Controls.OfType(Of HScrollBar).SingleOrDefault.Visible

于 2013-05-21T15:38:21.983 回答
3

只是给你一个想法(我现在没有时间,或者我面前的视觉工作室):

   For Each c In DataGridView1.Controls
        If c.GetType() Is GetType(VScrollBar) Then
            Dim vbar as VScrollBar= DirectCast(c, VScrollBar)
            If vbar.Visible = True Then
               'Do whatever you like
            End If
        End If
    Next
于 2013-05-21T15:37:57.920 回答
2

我以 Nianios 为例,进行了一些调整,并确定了滚动条是否可见。谢谢!

Private Function HScrollBarVisible() As Boolean
    Dim ctrl As New Control
    For Each ctrl In DataGridView1.Controls
        If ctrl.GetType() Is GetType(HScrollBar) Then
            If ctrl.Visible = True Then
                Return True
            Else
                Return False
            End If
        End If
    Next
    Return Nothing
End Function
于 2013-05-21T21:09:29.180 回答
2

这是滚动条可见性更改时引发事件的 VB.Net 版本,来自如何检测 DataGridView 控件中的垂直滚动条

Public Class MyGrid
  Inherits DataGridView

  Public Event ScrollbarVisibleChanged As EventHandler

  Public Sub New()
    AddHandler Me.HorizontalScrollBar.VisibleChanged, _
               AddressOf HorizontalScrollBar_VisibleChanged
  End Sub

  Public ReadOnly Property HorizontalScrollbarVisible() As Boolean
    Get
      Return HorizontalScrollBar.Visible
    End Get
  End Property

  Private Sub HorizontalScrollBar_VisibleChanged(sender As Object, e As EventArgs)
    RaiseEvent ScrollbarVisibleChanged(Me, EventArgs.Empty)
  End Sub
End Class
于 2013-05-21T15:43:03.197 回答