ASP - problem while setting background colour to picturebox

Asked By Roopal Jain on 06-Apr-11 06:05 AM

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?
Nikhil Mahajan replied to Roopal Jain on 06-Apr-11 06:24 AM
can u show us code you are that its easy to rectify the prblem
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);
            if (!dr.IsClosed)

            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].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")
                MessageBox.Show("added to starter");
              }// p1.BackgroundImage = img;

             else if (dr.GetValue(4).ToString()=="Desert")
                MessageBox.Show("added to desert");

              else if (dr.GetValue(4).ToString() == "Main Course")
                MessageBox.Show("added to main");
                MessageBox.Show("added to cld");


              cmd.CommandText = "Select * from RestMenu1";
              cmd.Connection = cnn;


          mcode = 1;
Nikhil Mahajan replied to Roopal Jain on 06-Apr-11 06:36 AM
you code is fine.. there is no problem with that....
i think ur command 
Select * from RestMenu1 where MenuCode='" + mcnt + "'
sometime dont have display that might be reason of not display the image.....
Roopal Jain replied to Nikhil Mahajan on 06-Apr-11 06:45 AM
if the image i have set is having width less than the picture box's width then it shows back color but both width are same then it doesnt show.....I have chosen image layout as a zoom then what can I overcome this problem