Suji D

Suji D

  • NA
  • 23
  • 7k

How to display images in picture box

May 29 2015 11:58 PM

Hi all,

Good Day! I am using C# in Visual Studio 2008. In this i have 9 picture boxes. in this picture box i want show the picture based on input value (input value taken from remote database). When i run this code i am getting pictures in form not in picture box. How to solve this problem.

for (int i = 0; i < 9; i++) { int pow_tag = Convert.ToInt32(Math.Pow(2, i)); string quryto = "Select fldTo&" + pow_tag + " from tmessage_temp where fldsno=IDENT_CURRENT('tmessage_temp')";                     cmd = new SqlCommand(quryto, cn);                     cmd.CommandType = CommandType.Text; string newqryto = "";                     newqryto = cmd.ExecuteScalar().ToString(); //MessageBox.Show(newqryto); Int32 Tovalue = Convert.ToInt32(newqryto); //MessageBox.Show("Tovalue:" + Tovalue);                     arrTotval[i] = Tovalue; // array for selected To's } string quryinput = "Select fldinput from tmessage_temp where fldSno=IDENT_CURRENT('tmessage_temp')"; SqlCommand exesql = new SqlCommand(quryinput, cn);                     exesql.CommandType = CommandType.Text; string newqryip = "";                     newqryip = exesql.ExecuteScalar().ToString(); Int32 Inputval = Convert.ToInt32(newqryip); switch (Inputval) { case 1: for (int j = 0; j < 9; j++) { if (arrTotval[j] > 0) {                                     picturbox[j].Image = itcdesignfinal.Properties.Resources.AllOk; this.Controls.Add(picturbox[j]); } } break; case 2: for (int j = 0; j < 9; j++) { if (arrTotval[j] > 0) {                                     picturbox[j].Image = itcdesignfinal.Properties.Resources.Maintain; this.Controls.Add(picturbox[j]); } } break; case 4: for (int j = 0; j < 9; j++) { if (arrTotval[j] > 0) {                                     picturbox[j].Image = itcdesignfinal.Properties.Resources.OutStan; this.Controls.Add(picturbox[j]); } } break; case 8: for (int j = 0; j < 9; j++) { if (arrTotval[j] > 0) {                                     picturbox[j].Image = itcdesignfinal.Properties.Resources.MaterialReq; this.Controls.Add(picturbox[j]); } } break; case 16: for (int j = 0; j < 9; j++) { if (arrTotval[j] > 0) {                                     picturbox[j].Image = itcdesignfinal.Properties.Resources._break; this.Controls.Add(picturbox[j]); } } break; case 32: for (int j = 0; j < 9; j++) { if (arrTotval[j] > 0) {                                     picturbox[j].Image = itcdesignfinal.Properties.Resources.QualityFocus; this.Controls.Add(picturbox[j]); } } break; } } catch (Exception ex) { MessageBox.Show(ex.Message); }
 

Answers (1)