0

我有一种感觉,我错过了一些明显的东西,但是:

我有一个表格中的单行图片,理论上这些图片可以永远持续下去。我需要一个滚动条,以便用户可以查看该行中的所有图片。我知道我需要启用自动滚动,但我不知道如何启用它。有人可以告诉我如何启用它或我缺少的东西吗?

如果有帮助,这是我用来生成图片的代码:

private void imagePalletToolStripMenuItem_Click(object sender, EventArgs e)
    {

        MyPalletGui.Show();

        Dictionary<string,Bitmap> MyPallet = MyImageCollection.ToDictionary();
        int xcor = -50;
        int ycor = 0;
        foreach (Bitmap curtImage in MyPallet.Values){
            PictureBox myPicBox = new PictureBox();
            xcor += 50;
            myPicBox.Location = new Point(xcor, ycor);
            myPicBox.Width = 50;
            myPicBox.Height = 50;
            myPicBox.Visible = true;
            myPicBox.Image = new Bitmap(curtImage);
            this.MyPalletGui.Controls.Add(myPicBox);
4

1 回答 1

2

此代码将完全按照您的意愿执行,它使用表单作为带有 AutoScroll 的 ViewPort:

public Form1()
{
InitializeComponent();

PopulatePictures();
}

private void PopulatePictures()
{
this.AutoScroll = true;

string[] list = Directory.GetFiles(@"C:\\Users\\Public\\Pictures\\Sample Pictures", "*.jpg");
PictureBox[] picturebox= new PictureBox[list.Length];
int y = 100;
  for (int index = 0; index < picturebox.Length; index++)
  {
  picturebox[index] = new PictureBox();
  this.Controls.Add(picturebox[index]);
  picturebox[index].Location=new Point(index * 120, y);
  if(x%12 == 0)
  y = y + 150;
  picturebox[index].Size = new Size(100,120);
  picturebox[index].Image = Image.FromFile(list[index]);
  }
}
于 2012-12-03T02:41:38.277 回答