0
Below I will try to give a value to the progressiBar that is in the class Controles
.
The method of Form1
, will call the class method ManipularProgressBar
to change the Control value ProgressBar
who’s in class Controles
.
But only that. when I get the progression controlBar which is in the instance and I assign a value, gives the following message: object reference not defined for an instance of an object.
This error occurs because I am defining a new instance of an object, there it returns null
. But just that, I don’t know how to best solve this problem. I don’t know exactly where to put the instance or if I need to instantiate.
I’m thinking of turning the class ManipularProgressBar
static or create a global instance of it so that all classes have access to the same value without resetting.
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; }
}
Better to say what you want because this code doesn’t seem to make the slightest sense and create a static class just seems to increase the common sense. The names of everything are too bad, no idea.
– Maniero