• Facebook
  • RSS Feed
  • Instagram
  • LinkedIn
  • Twitter
Oct 092011

I think I must deliberately not list steps in order.   In the last post I put :

  • Take as input a folder name
  • Scan that folder for image files (.png, .jpg, .jpeg, .tiff, .png – for now)
  • Add the picture boxes for each image found as I go along

What I actually ended up doing just now was the second and third parts of that, and not the first !

Here is what I modified the code with :-

string file = "";

int xcoord = startxpos;
int ycoord = startypos;

DirectoryInfo di = new DirectoryInfo(PathToScan);
FileInfo[] rgFiles = di.GetFiles("*.jpg"); // Just jpg's for now
foreach (FileInfo fi in rgFiles)
       file = fi.FullName;
       AddPictureBox(xcoord, ycoord, imagewidth, imageheight, file); 
       xcoord = xcoord + imagewidth + buffer;
       if (xcoord + imagewidth > this.Width) // new row
           xcoord = startxpos;
           ycoord = ycoord + imageheight + buffer;

So what this does it start at a particular path (PathToScan) looking for just JPG’s (for now)  and call the AddPictureBox function passing in the coordinates, and the full name of the file.

Some of the other changes involved moving the sizes and coordinates to start from up into constants higher up.  In fact, I don’t need to pass imagewidth, and imageheight to the AddPictureBox function, as the values of those variables is a/ constant, and b/ visible throughout the class now.

The AddPictureBox function hasn’t really changed, other than to take the parameter file, which is the full filename.

So the next thing that I need to do is to truly take the path to start scanning at as a parameter. 

    Time Spent So Far : 120 minutes



If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>