/// <summary> /// panel控件的事件:在向该控件添加控件时发生 /// </summary> private void panel1_ControlAdded(object sender, ControlEventArgs e) { panel1.AutoScroll = true; panel1.VerticalScroll.Enabled = true; panel1.VerticalScroll.Visible = true; panel1.Scroll += panel1_Scroll; } /// <summary> /// panel控件的事件:用户或代码滚动工作时发生 /// </summary> void panel1_Scroll(object sender, ScrollEventArgs e) { this.panel1.VerticalScroll.Value = e.NewValue; } private void Load(object sender, EventArgs e) { //注册panel1事件 this.panel1.ControlAdded += panel1_ControlAdded; for (int i = 0; i< 30; i++) { PictureBox pictureBox1 = new PictureBox(); pictureBox1.Cursor = Cursors.Hand; pictureBox1.Dock = DockStyle.Top; pictureBox1.Size = new Size(0, 100); pictureBox1.TabStop = false; pictureBox1.BorderStyle = BorderStyle.FixedSingle; this.panel1.Controls.Add(pictureBox1); } }