Solved

C# - Displaying Picture Boxes in Columns

Posted on 2007-04-05
11
215 Views
Last Modified: 2010-04-15
Hi guys 'n gals,

I want to modify my code to that it displays my Picture boxes in 2 Columns, rather than 2 Rows, could somebody help me out here please? Here is the code:

private void PopulateNodeCat()
        {
            MySqlConnection conn = new MySqlConnection(connString);
            DataSet ds = new DataSet();
            conn.Open();
            MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM tblNodeCat", conn);
            adapter.Fill(ds);
            conn.Close();

            int intX = panel2.Left + 2;
            int intY = panel2.Top + 2;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                PictureBox pb;
                pb = new PictureBox();
                pb.Name = "NodeCatPic_" + dr["UID"].ToString();
                pb.Height = 100;
                pb.Width = 100;
                pb.SizeMode = PictureBoxSizeMode.StretchImage;
                pb.Location = new Point(intX, intY);
                pb.Image = Image.FromFile("node_graphics\\" + dr["Filename"]);

                this.panel2.Controls.Add(pb);

                if (intY == panel2.Top + 2)
                {
                    intY = intY + 105;
                }
                else
                {
                    intY = panel2.Top + 2;
                    intX = intX + 105;
                }
            }
        }





Cheers!
0
Comment
Question by:Cyber-Drugs
  • 6
  • 5
11 Comments
 
LVL 5

Accepted Solution

by:
Yttribium earned 500 total points
ID: 18856932
                 if (intX == panel2.Left + 2)
                        {
                              intX = intX + 105;
                        }
                        else
                        {
                              intX = panel2.Left + 2;
                              intY = intY + 105;
                        }

would do what you want, with little change to your code.
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18856946
Shoot!

I just noticed what I did wrong now, mixed up the X and Y...

Cheers again... You may start to notice that I panic over the simplest of things, and end up asking questions on here for them... But sometimes I do get some nice tough ones! ;o)
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18856968
Well, time pressure makes even rather easy things seem 10 times more difficult!  If you get stuck on this kind of thing, it's probably best to get up stretch your legs and write on paper.  Often the answer stares in you in the face.
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18857642
I just got home to implement the code, here is the code at present for this:


                if (intY == 2)
                {
                    intX = intX + 52;
                }
                else
                {
                    intX = 2;
                    intY = intY + 52;
                }



and it doesn't give the correct result, have I done something slightly wrong? It's displaying everything in a single row at present...
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18857731
if (intX == panel2.Left + 2)
                        {
                              intX = intX + 52;
                        }
                        else
                        {
                              intX = panel2.Left + 2;
                              intY = intY + 52;
                        }
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18857775
I thought I needed to remove the panel2 part as to co-ordinates issue discussed in a previous question?

Anyway, the code you sent me just now displays only 1 of the images (so i'm guessing the others are hidden from view due to the panel?
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18857828
I was thinking the same thing, how did it creep back in??
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18857842
Earlier today I was at work without my laptop, so created new code to test what you answered.

Currently I am back home with my laptop which has the original code from last night.


:o)
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18857843
                       int intX = 2;
                        int intY = 2;
//CODE....
                        if (intX == 2)
                        {
                              intX = intX + 52;
                        }
                        else
                        {
                              intX = 2;
                              intY = intY + 52;
                        }
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18857874
Ok, that works, on to check the scrollbar, cheers for coming back and helping with this one. :o)
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18857891
no probs :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# GridRow get Old/New Value 1 55
which object should i use (efficiency) 5 46
ASP.NET 5 Templates 2 66
C# parent child form 5 19
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 is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

16 Experts available now in Live!

Get 1:1 Help Now