Hack Forums
[C#] Import multiple pictures into multiple pictureboxes - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Import multiple pictures into multiple pictureboxes (/showthread.php?tid=6213962)



Import multiple pictures into multiple pictureboxes - john ronaldsad - Jul 18, 2022

Hi, I want to import a folder of images (up to 45) into a layout of pictureboxes. I know how to import one picture into one picturebox but I have no clue how I would import a folder of images into a bunch of pictureboxes. Any and all help is appreciated!


RE: Import multiple pictures into multiple pictureboxes - HFDone - Jul 19, 2022

loop? https://stackoverflow.com/a/27796769


RE: Import multiple pictures into multiple pictureboxes - john ronaldsad - Jul 19, 2022

(Jul 19, 2022 02:29 AM)HFDone Wrote:  loop? https://stackoverflow.com/a/27796769

I'm getting an error

Code
Non-invocable member FileDialog. "FileNames" cannot be used like a method


Code
        private void Button1_Click(object sender, EventArgs e)
        {
            for (var x = 0; x < openFileDialog1.FileNames.Length; x++)
            {
                string Path = openFileDialog1.FileNames(x);
                switch (x)
                {
                    case 0:
                        PictureBox1.Image = Image.FromFile(Path);
                        break;
                    case 1:
                        PictureBox2.Image = Image.FromFile(Path);
                        break;
                    case 2:
                        PictureBox3.Image = Image.FromFile(Path);
                        break;
                    case 3:
                        PictureBox4.Image = Image.FromFile(Path);
                        break;
                }
            }
        }



RE: Import multiple pictures into multiple pictureboxes - HFDone - Jul 20, 2022

Code
// OpenFileDialog openFileDialog1 = new OpenFileDialog(); // if you didnt add
private void Button1_Click(object sender, EventArgs e)
{
    for (var x = 0; x < openFileDialog1.FileNames.Length; x++)
    {
        string Path = openFileDialog1.FileNames[x]; // Change
        switch (x)
        {
            case 0:
                PictureBox1.Image = Image.FromFile(Path);
                break;
            case 1:
                PictureBox2.Image = Image.FromFile(Path);
                break;
            case 2:
                PictureBox3.Image = Image.FromFile(Path);
                break;
            case 3:
            PictureBox4.Image = Image.FromFile(Path);
            break;
        }
    }
}



RE: Import multiple pictures into multiple pictureboxes - john ronaldsad - Jul 20, 2022

(Jul 20, 2022 07:45 AM)HFDone Wrote:  
Code
// OpenFileDialog openFileDialog1 = new OpenFileDialog(); // if you didnt add
private void Button1_Click(object sender, EventArgs e)
{
    for (var x = 0; x < openFileDialog1.FileNames.Length; x++)
    {
        string Path = openFileDialog1.FileNames[x]; // Change
        switch (x)
        {
            case 0:
                PictureBox1.Image = Image.FromFile(Path);
                break;
            case 1:
                PictureBox2.Image = Image.FromFile(Path);
                break;
            case 2:
                PictureBox3.Image = Image.FromFile(Path);
                break;
            case 3:
            PictureBox4.Image = Image.FromFile(Path);
            break;
        }
    }
}

Works! Thank you!