如何给Winform 的Panel控件添加滚动条

!!!!!!!!!!!!!真是太笨了,刚想起来,Panel控件还有一个AutoScoll属性,直接修改为true即可

 

添加Panel控件的如下两个事件即可:

*****当然,只是添加的竖向滚动条,横向滚动条只需把VerticalScroll改为HorizontalScroll即可

 

 

        ///


        /// panel控件的事件:在向该控件添加控件时发生
        ///

        ///
        ///
        private void pnlPlayerList_ControlAdded(object sender, ControlEventArgs e)
        {
            this.pnlPlayerList.VerticalScroll.Enabled = true;
            this.pnlPlayerList.VerticalScroll.Visible = true;
            this.pnlPlayerList.Scroll += pnlPlayerList_Scroll;

        }

        ///


        /// panel控件的事件:用户或代码滚动工作时发生 
        ///

        ///
        ///
        void pnlPlayerList_Scroll(object sender, ScrollEventArgs e)
        {
            this.pnlPlayerList.VerticalScroll.Value = e.NewValue;
        }

 


 

你可能感兴趣的:(C#自写控件,C#)