Cyber-Drugs
asked on
C# - Displaying Picture Boxes in Columns
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.Stretch Image;
pb.Location = new Point(intX, intY);
pb.Image = Image.FromFile("node_graph ics\\" + dr["Filename"]);
this.panel2.Controls.Add(p b);
if (intY == panel2.Top + 2)
{
intY = intY + 105;
}
else
{
intY = panel2.Top + 2;
intX = intX + 105;
}
}
}
Cheers!
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.Stretch
pb.Location = new Point(intX, intY);
pb.Image = Image.FromFile("node_graph
this.panel2.Controls.Add(p
if (intY == panel2.Top + 2)
{
intY = intY + 105;
}
else
{
intY = panel2.Top + 2;
intX = intX + 105;
}
}
}
Cheers!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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...
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...
if (intX == panel2.Left + 2)
{
intX = intX + 52;
}
else
{
intX = panel2.Left + 2;
intY = intY + 52;
}
{
intX = intX + 52;
}
else
{
intX = panel2.Left + 2;
intY = intY + 52;
}
ASKER
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?
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?
I was thinking the same thing, how did it creep back in??
ASKER
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)
Currently I am back home with my laptop which has the original code from last night.
:o)
int intX = 2;
int intY = 2;
//CODE....
if (intX == 2)
{
intX = intX + 52;
}
else
{
intX = 2;
intY = intY + 52;
}
int intY = 2;
//CODE....
if (intX == 2)
{
intX = intX + 52;
}
else
{
intX = 2;
intY = intY + 52;
}
ASKER
Ok, that works, on to check the scrollbar, cheers for coming back and helping with this one. :o)
no probs :)
ASKER
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)