简体   繁体   中英

Adding multiple Pictureboxes or labels with text and images

I want to have multiple cards with text and images or just red or blue color filled up. this is how the form should look like . So I am thinking about creating multiple picture boxes or labels But the problem is that the picture boxes are overlapping.

private void button1_Click(object sender, EventArgs e)
    {
        Createlabels();

    }
private void Createlabels()
    {
        var n = 5; 
        PictureBox[] p = new PictureBox[n];
        for (int i = 0; i < n; i++)
        {
            p[i] = new PictureBox();
            p[i].Image = Image.FromFile(@"C:\Users\sania\Desktop\c sharp project\red1.Png");

            p[i].SizeMode = PictureBoxSizeMode.Zoom;
            p[i].Left = i * 100;
            this.Controls.Add(p[i]);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Createlabels2();
    }
    private void Createlabels2()
    {
        var n = 10; 
        PictureBox[] q = new PictureBox[n];
        for (int j = 0; j < n; j++)

        {
            q[j] = new PictureBox();
            q[j].Image = Image.FromFile(@"C:\Users\sania\Desktop\c sharp project\blue.Png");
            q[j].SizeMode = PictureBoxSizeMode.Zoom;
            q[j].Left = j * 100;
            this.Controls.Add(q[j]);
        }
    }
}

This is the code I did so far my output but it should look like this one

    private void button1_Click(object sender, EventArgs e)
    {
        var n = 12;
        Button[] p = new Button[n];
        for (int i = 0; i < n; i++)
        {
            p[i] = new Button();
           p[i].Image = Image.FromFile(@"C:\Users\sania\Desktop\c sharp project\red1.Png");



            p[i].Text = i + " Reserved";

           p[i].Left = i * 100;
            this.Controls.Add(p[i])
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {

        Createlabels2();
    }
    private void Createlabels2()
    {
        var n = 12;
        Button[] q = new Button[n];
        for (int j = 0; j < n; j++)
        {
            q[j] = new Button();
            q[j].Image = Image.FromFile(@"C:\Users\sania\Desktop\c sharp project\blue.Png");


            //"ImagePanel" is a TableLayoutPanel
            q[j].Text = j + 10 + " Booked";
            q[j].Top = j * 100;
            this.Controls.Add(q[j]);
        }

    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM