Answered VScrollBar in custom control?

Adagio

Well-known member
Joined
Dec 12, 2005
Messages
162
Programming Experience
Beginner
Hi

I'm currently making a custom control that needs it's own scrollbar.
I'm using the OnPaint method of the control to paint what needs to be shown

The control needs to show a vertical ScrollBar under certain circumstances. I would prefer to use the VScrolBar that is already available, instead of having to paint my own

I thought it could be done a bit like this:

VB.NET:
Expand Collapse Copy
Public Class CustomList
    Inherits Control

Friend WithEvents VScrollBar1 As New System.Windows.Forms.VScrollBar

Public Sub New()       
        Me.VScrollBar1.Location = New System.Drawing.Point(Me.Width - 20, 10)
        Me.VScrollBar1.Name = "VScrollBar1"
        Me.VScrollBar1.Size = New System.Drawing.Size(20, Me.Height)
        Me.VScrollBar1.TabIndex = 1
        Me.Controls.Add(Me.VScrollBar1)
        Me.ResumeLayout()
End Sub

End Class

But the scrollbar is never shown


Any ideas on how to do this? Is it even possible?
 
Last edited:
VB.NET:
Expand Collapse Copy
Protected Overrides Sub OnClientSizeChanged(ByVal e As System.EventArgs)
    MyBase.OnClientSizeChanged(e)    
    Me.VScrollBar1.Location = New Point(Me.ClientSize.Width - Me.VScrollBar1.Width, 10)
    Me.VScrollBar1.Height = Me.ClientSize.Height - 10
End Sub
 
Back
Top