'How to solve picturebox1 is null?
I'm developing a demo that, for now, simply changes the width and height of a PictureBox according to the user's input.
For this to happen, the user inputs the data in one Windows Forms, and the PictureBox is in another PictureBox.
They exchange data via constructor as exemplified by this code:
if (pf.GetData().Item1 >= int.Parse(textBox1.Text) && pf.GetData().Item2 >= int.Parse(textBox2.Text))
{
PictureForm pbf = new PictureForm(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
pf.Show();
this.Hide();
}
in the first Form
public PictureForm(int newMaxX, int newMaxY)
{
pictureBox1.Width = newMaxX;
pictureBox1.Height = newMaxY;
}
and the constructor.
When I debut and input everything, this error message shows:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
pictureBox1 was null.
I really don't understand what's wrong. Can somebody help me with this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
