C# 给groupbox加滚动条

转自:http://blog.csdn.net/happy09li/article/details/7200746


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;

你可能感兴趣的:(C# 给groupbox加滚动条)