Reputation: 197
I have a Form
with a Panel
. In this Panel
, I want to use the vertical scrollbar
when I needed.
How do I do this? I've tried setting autoscroll
true and set a min scroll height, but the scrollbar never appears.
I've also tried this:
my_panel.ScrollBars = ScrollBars.Vertical
but then I get the error that scrollbar is not a member of my_panel
?
Thanks.
Upvotes: 1
Views: 2170
Reputation: 4312
I know You asked this question more then year ago, but... ;)
Recently, I had same problem (label inside panel, and I need only vertical scrollbar).
If You want only vertical scrollbar of panel with label inside, use code bellow :
Dim pnl As New Panel
pnl.Size = New Size(300, 200)
pnl.AutoSize = True
Dim lbl As New Label
lbl.Location = New Point(0, 0)
lbl.AutoSize = True
lbl.MaximumSize = New Size(pnl.Width - 18, 0)
'18 is approx. width of scroller, and height must be zero.
'even if Label is set to AutoSize, MaximumSize will not allow him to
'expand more then set width.
'Height of zero px will allow Label to expand as much as he need
pnl.Controls.Add(lbl)
Me.Controls.Add(pnl)
I hope this code help You.
btw. sorry for my weak English, I hope You will understand ;) :)
Upvotes: 0
Reputation: 67207
Autoscroll property is actually enough to achieve your need. Basically a panel with autoscroll
property true will display the scroll bar
only when the contents/components
inside that panel
exceeds over its bound. In other words, Scroll bar
appears with controls which have autoscroll
property set to true when the particular control's contents are larger than its visible
area. I think your panel is having some minimum amount of contents/controls which fits inside that panel's bound.
Upvotes: 1