[C#] 手動將 panel 加上 scrollbar

Sample Code 如下:

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

ScrollBar hScrollBar1 = new HScrollBar();
hScrollBar1.Dock = DockStyle.Bottom;
hScrollBar1.Scroll += (sender, e) => { panel1.HorizontalScroll.Value = hScrollBar1.Value; };
panel1.Controls.Add(hScrollBar1);

就可以手動的把 ScrollBar 指給 panel1 如下圖所示

留言