ReUp:在C#中的表单之间传递多张图片

问题描述 投票:0回答:1

我正在做我的学校项目,我无法从表格1传递到表格2来获取多张图片。更具体地说,在表格1上,用户将单击他们喜欢的任何图片,在下一张表格上,图片将缓慢显示。我尝试进行研究,但对于大多数主题,它们只能传递图像。这是我尝试放下每个pictureBox click事件的代码。这将运行,但是当我尝试单击图片时显示错误。

Form1

namespace CyberShop_Gia

{公共局部类Form1:表单{公共Form1(){InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        if(textBox1.Text == "")
        {
            MessageBox.Show("You've to enter your name first");
        }
        else
        {
            panel1.Visible = false;
            panel2.Visible = true;
            button1.Visible = false;
        }
    }
    private void pictureBox1_Click(object sender, EventArgs e)
    {
        pictureBox2.Visible = false;
        pictureBox3.Visible = false;
        PictureBox pb = pictureBox1 as PictureBox;
        Form2 f1 = new Form2(pb.Image, textBox1.Text);
        f1.Show();
    }
    private void pictureBox2_Click(object sender, EventArgs e)
    {
        pictureBox1.Visible = false;
        pictureBox3.Visible = false;
        PictureBox pb1 = pictureBox2 as PictureBox;
        Form2 f2 = new Form2(pb1.Image, textBox1.Text);
        f2.Show();
    }
    private void pictureBox3_Click(object sender, EventArgs e)
    {
        pictureBox2.Visible = false;
        pictureBox1.Visible = false;
        PictureBox pb2 = pictureBox3 as PictureBox;
        Form2 f3 = new Form2(pb2.Image, textBox1.Text);
        f3.Show();
    }
}

}

Form2

public partial class Form2 : Form
{
    public Form2(Image pic, string username)
    {
        label1.Text = "Welcome " + username; 
        InitializeComponent();
        pictureBox1.Image = pic;
    }

当我尝试单击表格1上的任何图片时,这是the error,错误的完整细节可以看到here

c# winforms
1个回答
0
投票

PictureBox类的文档说明:

热门问题
推荐问题
最新问题