У меня есть несколько блоков изображений, которые я могу добавить динамически, но мне нужно 3 изображения в ряд, и если число изображений превышает число 3, четвертое изображение должно быть ниже первого изображения и т. Д.
[1] : https://i.stack.imgur.com/yFzCr.png (Изображение того, что у меня есть)
[2]: https://i.stack.imgur.com/3tmHj.png (Изображение того, что я хочу)
Код: -
if (ward.Text == "Aged Care - Dementia Ward")
{
int Left = 79;
int bedLeft = 170;
int Top = 224;
int bedTop = 377;
bedDatagridview bed = new Electronic_Medical_Record_System.bedDatagridview();
if (bed.dementia.Rows.Count < 3)
{
for (int i = 0; i < bed.dementia.Rows.Count; i++)
{
PictureBox green = new PictureBox();
Bitmap image = new Bitmap("E:\\Projects\\Personal\\EMRS\\Assets\\png\\bed-green.png");
green.Image = (Image)image;
green.Location = new System.Drawing.Point(Left, Top);
green.Name = "pictureBox1";
green.Size = new System.Drawing.Size(250, 150);
green.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
green.TabIndex = 30;
green.TabStop = false;
green.Cursor = Cursors.Hand;
PictureBox red = new PictureBox();
Bitmap image1 = new Bitmap("E:\\Projects\\Personal\\EMRS\\Assets\\png\\bed-red.png");
red.Image = (Image)image1;
red.Location = new System.Drawing.Point(Left, Top);
red.Name = "pictureBox1";
red.Size = new System.Drawing.Size(250, 150);
red.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
red.TabIndex = 30;
red.TabStop = false;
red.Cursor = Cursors.Hand;
PictureBox blue = new PictureBox();
Bitmap image2 = new Bitmap("E:\\Projects\\Personal\\EMRS\\Assets\\png\\bed-blue.png");
blue.Image = (Image)image2;
blue.Location = new System.Drawing.Point(Left, Top);
blue.Name = "pictureBox1";
blue.Size = new System.Drawing.Size(250, 150);
blue.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
blue.TabIndex = 30;
blue.TabStop = false;
blue.TabStop = false;
blue.Cursor = Cursors.Hand;
Label lbl = new Label();
lbl.AutoSize = true;
lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lbl.Location = new System.Drawing.Point(bedLeft, bedTop);
lbl.Name = "label7";
lbl.Size = new System.Drawing.Size(69, 16);
lbl.TabIndex = 31;
lbl.Text = bed.dementia.Rows[i].Cells[1].Value.ToString();
Left += 400;
bedLeft += 400;
Controls.Add(lbl);
Controls.Add(green);
Controls.Add(red);
Controls.Add(blue);
if (bed.dementia.Rows[i].Cells[2].Value.ToString() == "Available")
{
green.BringToFront();
}
else if (bed.dementia.Rows[i].Cells[2].Value.ToString() == "Occupied")
{
red.BringToFront();
}
else if (bed.dementia.Rows[i].Cells[2].Value.ToString() == "Reserved")
{
blue.BringToFront();
}
}
}
else
{
for (int i = 0; i < bed.dementia.Rows.Count; i++)
{
PictureBox green = new PictureBox();
Bitmap image = new Bitmap("E:\\Projects\\Personal\\EMRS\\Assets\\png\\bed-green.png");
green.Image = (Image)image;
green.Location = new System.Drawing.Point(Left, Top);
green.Name = "pictureBox1";
green.Size = new System.Drawing.Size(250, 150);
green.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
green.TabIndex = 30;
green.TabStop = false;
green.Cursor = Cursors.Hand;
PictureBox red = new PictureBox();
Bitmap image1 = new Bitmap("E:\\Projects\\Personal\\EMRS\\Assets\\png\\bed-red.png");
red.Image = (Image)image1;
red.Location = new System.Drawing.Point(Left, Top);
red.Name = "pictureBox1";
red.Size = new System.Drawing.Size(250, 150);
red.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
red.TabIndex = 30;
red.TabStop = false;
red.Cursor = Cursors.Hand;
PictureBox blue = new PictureBox();
Bitmap image2 = new Bitmap("E:\\Projects\\Personal\\EMRS\\Assets\\png\\bed-blue.png");
blue.Image = (Image)image2;
blue.Location = new System.Drawing.Point(Left, Top);
blue.Name = "pictureBox1";
blue.Size = new System.Drawing.Size(250, 150);
blue.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
blue.TabIndex = 30;
blue.TabStop = false;
blue.TabStop = false;
blue.Cursor = Cursors.Hand;
Label lbl = new Label();
lbl.AutoSize = true;
lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lbl.Location = new System.Drawing.Point(bedLeft, bedTop);
lbl.Name = "label7";
lbl.Size = new System.Drawing.Size(69, 16);
lbl.TabIndex = 31;
lbl.Text = bed.dementia.Rows[i].Cells[1].Value.ToString();
//Left += 400;
//bedLeft += 400;
Top += 200;
bedTop += 200;
Controls.Add(lbl);
Controls.Add(green);
Controls.Add(red);
Controls.Add(blue);
if (bed.dementia.Rows[i].Cells[2].Value.ToString() == "Available")
{
green.BringToFront();
}
else if (bed.dementia.Rows[i].Cells[2].Value.ToString() == "Occupied")
{
red.BringToFront();
}
else if (bed.dementia.Rows[i].Cells[2].Value.ToString() == "Reserved")
{
blue.BringToFront();
}
}
}