Solved

Array of Picturebox

Posted on 2006-11-28
1
481 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 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

Technology Partners: 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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