Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Array of Picturebox

Posted on 2006-11-28
1
Medium Priority
?
483 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
[X]
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
1 Comment
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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