将不同目录中的图像加载到滚动面板

本文关键字:加载 滚动 图像 | 更新日期: 2023-09-27 18:32:23

我正在实现一个应用程序:

  • 在以下情况下自动将图像从"我的图片"文件夹加载到面板表单已加载。(你可以在这里找到代码)

  • 我的程序中还有另一个功能是:打开文件夹,使用户能够打开一个文件夹以将其图像也加载到同一面板。

我的问题是:每当我选择打开一个新文件夹时,该文件夹的图像会出现在"我的图片"文件夹的图像,我知道问题是什么,但我不知道如何解决。

用于从"我的图片"自动加载图像的代码包含一个名为 Position 的变量,该变量定义当前 PictureBox 控件的位置,其初始值为 0。

//2 variables, one for the Y position of the current PictureBox control
            //and one for help count the number of images in the directory
            int position = 0;
            int count = 0;

打开文件夹的代码与我从"我的图片"加载图像时使用的代码相同,位置初始值也是 0!这就是为什么新加载的图像显示在旧图像下的原因。

private void openFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "Getting files.....";
            int position = 0;
            int count = 0;

如何解决此问题?我想保存最新创建的PictureBox的位置,然后将其用作private void openFolderToolStripMenuItem_Click的初始值

谢谢!

将不同目录中的图像加载到滚动面板

尝试这样做

        int position = 0;
        int count = 0;
        private void openFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "Getting files.....";
            //your work
        }

所以当你再次调用这个位置时,位置不会是'0'''

编辑我读了那个链接

PictureBox pb = new PictureBox();

您动态创建的控件,用于删除旧图像执行此操作

private void openFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
        foreach (Control ctrl in this.Controls)
        {
            if (ctrl is PictureBox)
                this.Controls.Remove(ctrl);
        }
        //Your code