給groupbox加滾動條。。
阿新 • • 發佈:2019-01-22
public Form4()
{
InitializeComponent();
foreach (Control gbox in groupBox1.Controls)
{
if (gbox is VScrollBar) continue;
gbox .Tag = panel.Location.Y;
}
}
新增一個vScrollBar控制元件,加上此事件
private void vScrollBar2_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);
}
}
另外將panel的AutoScroll的屬性設為ture就可以顯示滾動條了了
將滾動條位置置於最低端
pnlMessage.VerticalScroll.Value = pnlMessage.VerticalScroll.Maximum;