?
Solved

Array of Picturebox

Posted on 2006-11-28
1
Medium Priority
?
482 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 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