这是我的Designer.cs代码。
this.gbFacets.Location = new System.Drawing.Point(590, 69);
this.gbFacets.Name = "gbFacets";
this.gbFacets.Size = new System.Drawing.Size(255, 355);
this.gbFacets.TabIndex = 7;
this.gbFacets.TabStop = false;
this.gbFacets.Text = "Facets Found";
this.gbFacets.Enter += new System.EventHandler(this.gbFacets_Enter);
这是我的Formmain代码
private void AddFacetsToPictureBoxes(List<PictureBox> pictureBoxes)
{
foreach (var pic in pictureBoxes)
this.gbFacets.Controls.Add(pic);
}
我将图片添加到Groupbox,但如果没有图片增加,那么它只显示一些图片。所以请告诉我如何使这个组框可滚动查看所有图片。
答案 0 :(得分:1)
由于groupbox没有可滚动属性,因此请将图像添加到面板中,并设置可滚动属性。
然后让面板填充组框。
编辑:类似这样的事情
private void AddPicturesToGroupBox(List<PictureBox> pictureBoxes)
{
Panel myPanel = new Panel();
myPanel.Dockstyle = Dockstyle.Fill;
myPanel.AutoScroll = true; //this allows the panel to display scrollbars when it needs to
foreach (var pic in pictureBoxes)
{
myPanel.Controls.Add(pic); //put your pictures onto the panel
}
this.gbFacets.Controls.Clear();
this.gbFacets.Controls.Add(myPanel); //put your panel inside the Groupbox
}