System.NullReferenceException: 'Object reference not set to an instance of an object.'

0
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 Market
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            Calculadora_Panel.Visible = true;
            panel3.Visible = false;
            panel4.Visible = false;
            InitializeComponent();

}
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 Market
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            Calculadora_Panel.Visible = true;
            panel3.Visible = false;
            panel4.Visible = false;
            InitializeComponent();

        }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 Calculadora = new Form2();
        Calculadora.Show();
        Calculadora_Panel.Visible = true;
        panel3.Visible = false;
        panel4.Visible = false;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Form3 PLista = new Form3();
        PLista.Show();
        Calculadora_Panel.Visible = false;
        panel3.Visible = true;
        panel4.Visible = false;
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Calculadora_Panel.Visible = false;
        panel3.Visible = false;
        panel4.Visible = true;
    }

    private void button4_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    void otherForm_FormClosed(object sender, FormClosedEventArgs e)
    {
        this.Show();
    }

    private void About_buttom_Click(object sender, EventArgs e)
    {
        AboutBox1 About = new AboutBox1();
        About.Show();
    }

    private void button1_Click_1(object sender, EventArgs e)
    {

    }
}

}

    
asked by anonymous 08.04.2018 / 02:00

2 answers

1

First of all, you could have added your code to your question using the Edit function. I did not try to look at buttons and design in general, but rather at the problem.

From what you can perceive its error probably should be this:

YoucanavoidthisbyusingthepropertiesofthecontrolsaftertheInitializeComponents()method,sincethisiswheretheFormscomponentsareinstalled:

AnotheralternativeistomakechangestoEventLoad:

ToknowwhathappensintheInitializeComponent()method,youcandouble-clicktheFormN.Designer.csfile:

    
08.04.2018 / 10:34
0

Should the panel3 and panel4 variables reference instances of the PanelPanel object, reference elements belonging to PanPanel Calculator, or what other classes? You have not declared the initialization of objects in any part of the posted code, so you can not assign value to the attributes of the objects. If you are trying to modify a static attribute, then you should not do this through an instance of the object

panel3 = new Calculadora_Panel(atributos);
panel4 = new Calculadora_Panel(atributos);

If this is not the problem, you need to better detail your issue and post the rest of your code so we can resolve the issue.

    
08.04.2018 / 02:09