簡體   English   中英

添加多個帶有文本和圖像的圖片框或標簽

[英]Adding multiple Pictureboxes or labels with text and images

我想要多張帶有文字和圖像的卡片,或者只填充紅色或藍色。 這就是表單的外觀 所以我正在考慮創建多個圖片框或標簽但問題是圖片框是重疊的。

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]);
        }
    }
}

這是我到目前為止所做的代碼output但它應該看起來像這個

    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]);
        }

    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM