0

I have added a scroll bar programmatically to a panel in my form, however when i run the application the scroll bar doesn't do anything.

How do I get it to scroll up and down the panel?

Much appreciated.

pnlGantt.Visible = true;
ScrollBar vScrollBar1 = new VScrollBar();
vScrollBar1.Dock = DockStyle.Right;
vScrollBar1.Scroll += (sender, e) => { pnlGantt.VerticalScroll.Value = vScrollBar1.Value; };
pnlGantt.Controls.Add(vScrollBar1);

Panel: enter image description here

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
NickB6
  • 209
  • 2
  • 5
  • 16

1 Answers1

0

What is your content you want to scroll placed in? Is it a StackPanel? Your scrollbar does not know about the size of the content/panel it is supposed to control.

Try to put your content (the pnlGantt) inside a ScrollViewer in XAML instead. Right now you are placing the scrollbar inside the pnlGantt.

Niklas Bjorkman
  • 678
  • 5
  • 8