Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. picture box - help!!

picture box - help!!

Scheduled Pinned Locked Moved C#
helpgraphicstutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    printscreen12345
    wrote on last edited by
    #1

    How to display all the image files in a directory? Even with the for loop below, I only get one image file displayed. I don't know if the problem lies in the location of the picturebox1. Can anyone please help? int y = 5; foreach (String file in files) { if (file.Contains(".jpg")) { System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); picture.Controls.Add(pictureBox1); pictureBox1.ImageLocation = file; pictureBox1.Location = new System.Drawing.Point(6, y); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; y = y + pictureBox1.Size.Height + 5; } }

    G N 2 Replies Last reply
    0
    • P printscreen12345

      How to display all the image files in a directory? Even with the for loop below, I only get one image file displayed. I don't know if the problem lies in the location of the picturebox1. Can anyone please help? int y = 5; foreach (String file in files) { if (file.Contains(".jpg")) { System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); picture.Controls.Add(pictureBox1); pictureBox1.ImageLocation = file; pictureBox1.Location = new System.Drawing.Point(6, y); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; y = y + pictureBox1.Size.Height + 5; } }

      G Offline
      G Offline
      Graham Nimbley
      wrote on last edited by
      #2

      Hi, I can't see anything wrong with the code above. What control is picture? I'm assuming it's a panel or something. Might be handy to post the code used to gain the list of files.

      P 1 Reply Last reply
      0
      • P printscreen12345

        How to display all the image files in a directory? Even with the for loop below, I only get one image file displayed. I don't know if the problem lies in the location of the picturebox1. Can anyone please help? int y = 5; foreach (String file in files) { if (file.Contains(".jpg")) { System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); picture.Controls.Add(pictureBox1); pictureBox1.ImageLocation = file; pictureBox1.Location = new System.Drawing.Point(6, y); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; y = y + pictureBox1.Size.Height + 5; } }

        N Offline
        N Offline
        Nader Elshehabi
        wrote on last edited by
        #3

        Do you mean you get just one PictureBox with one image, or many PictureBoxes all with the same image?

        P 1 Reply Last reply
        0
        • G Graham Nimbley

          Hi, I can't see anything wrong with the code above. What control is picture? I'm assuming it's a panel or something. Might be handy to post the code used to gain the list of files.

          P Offline
          P Offline
          printscreen12345
          wrote on last edited by
          #4

          It's a tabpage control. I debug it through and found that the size of the picture box has not changed to the size of the picture (I guess this is what it should be by using autosize mode). From this I would assume the new picture box is added on top of the existing one with exactly the same size each time.....

          1 Reply Last reply
          0
          • N Nader Elshehabi

            Do you mean you get just one PictureBox with one image, or many PictureBoxes all with the same image?

            P Offline
            P Offline
            printscreen12345
            wrote on last edited by
            #5

            It seems to me that the new picture box is added on top of the existing one with exactly the same size each time. That's why I only see one image. Setting the sizemode to autosize doesn't change the size of the picture box??

            N 1 Reply Last reply
            0
            • P printscreen12345

              It seems to me that the new picture box is added on top of the existing one with exactly the same size each time. That's why I only see one image. Setting the sizemode to autosize doesn't change the size of the picture box??

              N Offline
              N Offline
              Nader Elshehabi
              wrote on last edited by
              #6

              Hello If I were you I'd use a foreach loop to check the parent.Controls for the next: 1- Make sure that the pictureboxes are all added up tto the parent successfully 2- Make sure of the ImageLocation property of each Picturebox 3- The size and location of each picturebox This may clarify the problem. If it's like you said, simply calculate the size manually each time by calculating the image's size -ie. don't rely on AutoSize" Happy programming;)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups