Below I'll try to give a value to the progressBar that is in the Controles
class.
The method of Form1
, will call the method of class ManipularProgressBar
to change the value of Control ProgressBar
that is in class Controles
.
But just ... when I get the progressBar control that is in the instance and assigns a value, it gives the following message: Object reference not set to an instance of an object.
This error occurs because I'm setting a new instance of an object, and it returns null
. But just that, I do not know how best to solve this problem. I do not know exactly where to put the instance or if I need to instantiate.
I'm thinking of transforming the class ManipularProgressBar
into static or creating an instance of it global so that all classes have access to the same value without reset.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Controles controls = new Controles();
ManipularProgressBar mp = new ManipularProgressBar();
controls.progressBar = this.progressBar1;
mp.editProgressBar();
}
}
public class ManipularProgressBar
{
public void editProgressBar()
{
Controles controls = new Controles();
controls.progressBar.Value = 50;
}
}
public class Controles
{
public ProgressBar progressBar { get; set; }
}