public Form3() { InitializeComponent(); foreach (Control gbox in groupBox1.Controls) { if (gbox is VScrollBar) continue; gbox.Tag = gbox.Location.Y; } panelControl1.VerticalScroll.Value = panelControl1.VerticalScroll.Maximum; }
然后加入一个垂直滚动条控件,并添加如下事件:
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e) { foreach (Control gbox in groupBox1.Controls) { if (gbox is VScrollBar) continue; gbox.Location = new Point(gbox.Location.X, (int)gbox.Tag - e.NewValue); } }
注意:给groupbox 的父panel 设置AutoScroll=true