I implemented a ScrollableControl and only want vertical scrolling. Every time I make the form smaller then the control
the control has h scroll bars even though I set it to false. I have the control anchored to all four corners. I watched the resize event and for some reason even if i keep setting hscroll to false it gets set back to true.
Thanks!
FromMSDN.
To manually override which scroll bars are visible, set the VScroll and HScroll properties. If either property is set to false, the corresponding scroll bar will not be visible, even if the AutoScroll property is set to true.
Public Class TestControl
Inherits System.Windows.Forms.ScrollableControl
Implements IContainerControl
Private myActiveControl As Control
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
' Make the container scrollable.
'Add any initialization after the InitializeComponent() call
Me.AutoScroll = True
Me.VScroll = True
Me.HScroll = False
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
#End Region
' Add implementation to the IContainerControl.ActiveControl property.
Public Property ActiveControl() As Control Implements IContainerControl.ActiveControl
Get
Return Me.myActiveControl
End Get
Set(ByVal Value As Control)
' Make sure the control is a member of the ControlCollection.
If Me.Controls.Contains(value) Then
Me.myActiveControl = value
End If
End Set
End Property
' Add implementation to the IContainerControl.ActivateControl(Control) method.
Public Function ActivateControl(ByVal active As Control) As Boolean Implements IContainerControl.ActivateControl
If Me.Controls.Contains(active) Then
' Select the control and scroll the control into view if needed.
active.Select()
Me.ScrollControlIntoView(active)
Me.myActiveControl = active
Return True
End If
Return False
End Function
Public Property MyHScroll() As Boolean
Get
Return Me.HScroll
End Get
Set(ByVal Value As Boolean)
Me.HScroll = Value
End Set
End Property
End Class