private void LoadData() { flowLayoutPanel1.Controls.Clear(); int i; cn.Open(); cm = new SqlCommand("select photo,Barcod,Name,Price from Items ", cn); dr = cm.ExecuteReader(); while (dr.Read()) { long len = dr.GetBytes(0, 0, null, 0, 0); byte[] array = new byte[System.Convert.ToInt32(len) + 1]; dr.GetBytes(0, 0, array, 0, System.Convert.ToInt32(len)); pic = new PictureBox(); pic.Width = 70; pic.Height = 100; pic.BorderStyle = BorderStyle.Fixed3D; pic.BackgroundImageLayout = ImageLayout.Stretch; pic.Tag = dr["Barcod"].ToString(); Name = new Label(); Name.Text = dr["Name"].ToString(); Name.BackColor = Color.FromArgb(46, 134, 222); Name.TextAlign = ContentAlignment.MiddleCenter; Name.Dock = DockStyle.Bottom; Name.ForeColor = Color.White; Name.Tag = dr["Barcod"].ToString(); Price = new Label(); Price.Text = dr["Price"].ToString(); Price.Width = 30; Price.BackColor = Color.FromArgb(255, 121, 121); Price.TextAlign = ContentAlignment.MiddleCenter; MemoryStream ms = new MemoryStream(array); Bitmap bitmap = new Bitmap(ms); pic.BackgroundImage = bitmap; pic.Controls.Add(Name); pic.Controls.Add(Price); flowLayoutPanel1.Controls.Add(pic); pic.Cursor = Cursors.Hand; pic.Click += new EventHandler(OnClick); //pic.Click += (sender, e) => OnClick(this, e, pic.Tag.ToString()); //Price.Click += (sender, e) => OnClick(this, e, Price.Tag.ToString()); } dr.Close(); cn.Close(); }