Solved

Array of Picturebox

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now