Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Array of Picturebox

Posted on 2006-11-28
1
479 Views
Last Modified: 2010-04-16
I am trying to place on a form a dynamic column of images - the name of the image is from a database. The code below compiles OK but does not display the pictureboxes. Any help would be appreciated
___________________________________________________________________________________________________________________________
 DataTable dt = dset.Tables[0];
           
 DataRow[] foundRows;
 string strExpr = "true";

 // Sort ascending by column named Overlap.

            string strSort = "Overlap ASC";

// Use the Select method to find all rows matching the filter.

            foundRows = dt.Select(strExpr, strSort);

            int rcount=dt.Rows.Count;
//create the correct number of pictureboxes in the array

            PictureBox[] pboxes = new PictureBox[rcount];

//initialise counter
 int outcount = 0;

//loop through each datarow

            foreach (DataRow drow in foundRows)
            {
               
              //find the top position for the picturebox

              int pos_image = 10 + (outcount * 220);

                //load the bitmap

                string bmap_location = drow.ItemArray[6].ToString();          // drow.ItemArray[6] is the filename
                try
                {
                   
           
                    Bitmap bmap = new Bitmap(bmap_location);
           
                    PictureBox tempbox = new PictureBox();


                    //get the longest dimension and modify the picture box so smaller but with correct aspect ration
                   
                   if (bmap.Width >= bmap.Height)
                    {
                        tempbox.Width = 200;
                        decimal dival1 = Decimal.Divide(200,bmap.Width);
                        tempbox.Height = Convert.ToInt32(dival1*bmap.Height);
                    }
                    else
                    {
                        tempbox.Height = 200;
                        decimal dival1 = Decimal.Divide(200, bmap.Height);
                        tempbox.Width = Convert.ToInt32(dival1 * bmap.Width);
                    }

                    //each photo 20 pixels from the form left hand side
                    tempbox.Left = 20;

                    //picture top to derived location
                    tempbox.Top = pos_image;

                   // load the bmp into the image
                    tempbox.Image = bmap;

                    //make visible
                    tempbox.Visible = true;


                    //load the array picturebox with the created picturebox
                    pboxes[outcount] = tempbox;

                    outcount++;

                }
                catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                   
                    }


            }




0
Comment
Question by:Linking
1 Comment
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 250 total points
ID: 18033621
It seems you never add your picture boxes to th form.

Try to add like:

myForm.Controls.Add(tempbox )
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question