ASP - problem while setting background colour to picturebox
Asked By Roopal Jain on 06-Apr-11 06:05 AM
hi
I have dynamically added pictureboxes to win form,also I have set backColor property to these picturebox,but some picturebox doesnt shows the backcolor I have set,Why?
how to overcome this problem?
Roopal Jain replied to Nikhil Mahajan on 06-Apr-11 06:30 AM
ok....on click event of tabcontrol I have written this code.....
cmd.CommandText = "select count(*) from RestMenu1";
int c = Convert.ToInt32(cmd.ExecuteScalar());
// MessageBox.Show("cntr :" + c);
PictureBox[] pb = new PictureBox[c];
if (c > 0)
{
cmd.CommandText = "Select Max(menucode) from RestMenu1";
mcode = Convert.ToInt32(cmd.ExecuteScalar());
MenuArray = new string[c];
MenuCntr = new Boolean[c];
int mcnt = 1;
for (int i = 0; i < c; i++)
{
MenuCntr[i] = true;
//MessageBox.Show("i" + i);
mcode++;
if (!dr.IsClosed)
dr.Close();
cmd.CommandText = "Select * from RestMenu1 where MenuCode='" + mcnt + "'";
dr = cmd.ExecuteReader();
if (dr.Read())
{
string p = dr.GetValue(5).ToString();
//MessageBox.Show("IL " + p);
byte[] imageData = ReadFile(p);//ReadFile is User Defined Method;
// pb[i].ImageLocation = p;
pb[i].BackColor = Color.Blue;
//Image img =(Image) dr.GetValue(6);
string m1 = dr.GetValue(1).ToString();
pb[i] = new PictureBox();
pb[i].BackgroundImageLayout = ImageLayout.Zoom;
pb[i].SizeMode.Equals("Normal");
pb[i].ImageLocation = p;
pb[i].Name = m1;
MenuArray[i] = m1;
pb[i].Click += new EventHandler(PictureBox_Click);
pb[i].MouseDown += new MouseEventHandler(PictureBox_MouseDown);
if (dr.GetValue(4).ToString()=="Starter")
{
flowLayoutPanelStarter.Controls.Add(pb[i]);
MessageBox.Show("added to starter");
}// p1.BackgroundImage = img;
else if (dr.GetValue(4).ToString()=="Desert")
{
flowLayoutPanelDesert.Controls.Add(pb[i]);
MessageBox.Show("added to desert");
}
else if (dr.GetValue(4).ToString() == "Main Course")
{
flowLayoutPanelMainCourse.Controls.Add(pb[i]);
MessageBox.Show("added to main");
}
else
{
flowLayoutPanelColdDrink.Controls.Add(pb[i]);
MessageBox.Show("added to cld");
}
dr.Close();
cmd.CommandText = "Select * from RestMenu1";
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
++mcnt;
}
}
}
else
{
mcode = 1;
}