According to codes below, I can gather my stored images from my SQL server table and put a CheckBox under each of them.My aim is to use these CheckBoxes to select images above them and take an action with another user control (i.e. button for erasing them from DB or copying them to another directory).I tried to create an event handler but cannot achieve with my level of c# knowledge. I kindly ask for a solution and guidance for better understanding.
private void button4_Click(object sender, EventArgs e)
{
PictureBox[] pba = new PictureBox[100];
SqlConnection con4 = new SqlConnection(DBHandler.GetConnectionString());
SqlCommand cmd4 = new SqlCommand("ReadAllImage", con4);
cmd4.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da2 = new SqlDataAdapter(cmd4);
DataSet dt2 = new DataSet("ImageData");
da2.SelectCommand = cmd4;
da2.Fill(dt2);
int a = comboBox1.Items.Count;
byte[] xdata = new byte[0];
CheckBox[] chckbx = new CheckBox[400];
for (var i = 0; i < a; i++)
{
DataRow myRow2 = null;
if (myRow2 == null)
{
myRow2 = dt2.Tables[0].Rows[i];
xdata = (byte[])myRow2["ImageData"];
MemoryStream stream2 = new MemoryStream(xdata);
PictureBox npb = new PictureBox();
npb.Size = new Size(60, 60);
int b = i / 5;
npb.Location = new Point(420 + (i % 5) * 70, 20 + (90 * b));
npb.Image = Image.FromStream(stream2);
npb.SizeMode = PictureBoxSizeMode.StretchImage;
pba[i] = npb;
this.Controls.Add(pba[i]);
CheckBox chckbxx = new CheckBox();
chckbxx.Location = new Point(420 + (i % 5) * 70, 80 + (90 * b));
chckbxx.AutoSize = true;
chckbx[i] = chckbxx;
this.Controls.Add(chckbx[i]);
}
my example output after running the codes.I wanna use the chekckboxes like in this pic.I actually managed to create them like this but couldn't make them related with images above them.
Aucun commentaire:
Enregistrer un commentaire