I doing my school project and i can't get multiple pictures from form 1 passing to form 2. More specifically, on form 1, users will click on any pictures they liked and on the next form, the picture will slowly show. I've tried to research but for most of the topic outside, they can only pass an image. This is the code i try to put down on every pictureBox click event. This will run but showing error when i try to click on picture.
Form1:
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)
{
InitializeComponent();
pictureBox1.Image = pic;
}
}
Edit: This is the error when i tried to click on any picture on form 1, and the full detail of the error can be seen here