2013-05-21 27 views

回答

2

只給你一個想法(我沒有時間,現在,還是在我的面前視覺工作室):

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 
+0

我拿了你的例子,做了一些調整,並確定滾動條是否可見。謝謝! – Rose

+0

對不起,如果代碼不完全正確,但我建立在我的腦海。 – Nianios

5

試試這個:

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

+0

選定的答案是正確的,但這對我來說是一個更清潔的方法。 'Dim DGVVerticalScroll = MyDataGridViewControl.Controls.OfType(Of VScrollBar).SingleOrDefault' – Mayhem

+0

UpVote from me,for this elegant solution – Nianios

2

這裏是VB .Net版提升事件時滾動條的可見性發生變化,從How to detect the vertical scrollbar in a DataGridView control

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