I want to change a picture box from form1 with form2 but keep getting this error ,couldnt understand how to fix it even with all the ppl asking about this error, if anyone could help please. photo of the error
I have tried making it all static but it didnt work.
Form 1
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string solution = "ashe";
public void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == solution || pictureBox1.Image == Image.FromFile(@"C:\Users\User\Desktop\lol\azir.png"))
{
pictureBox1.Image = Image.FromFile(@"C:\Users\User\Desktop\lol\azir.png");
}
if (textBox1.Text == solution || pictureBox1.Image == Image.FromFile(@"C:\Users\User\Desktop\lol\sej.png"))
{
pictureBox1.Image = Image.FromFile(@"C:\Users\User\Desktop\lol\sej.png");
var form2 = new Form2();
form2.Show();
this.Hide();
}
else
{
pictureBox1.Image = Image.FromFile(@"C:\Users\User\Desktop\lol\x.jpg");
}
}
public void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(@"C:\Users\User\Desktop\lol\azir_black.png");
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
}
Form 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
int count = 0;
public void button2_Click(object sender, EventArgs e)
{
count++;
switch (count)
{
case 1:
Form1.pictureBox1.Image = Image.FromFile(@"C:\Users\Ucenik\Desktop\lol\sej_black.png");
Form1.solution = "sejuani";
var form1 = new Form1();
form1.Show();
this.Hide();
break;
default:
break;
}
}
}
}
.........................................................