System.Nullreferenceexception: 'Undefined object reference for an instance of an object. '

Asked

Viewed 99 times

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)
    {

    }
}

}

2 answers

1

First of all, you could have added your code to your question using the Edit function. I did not try to pay attention to buttons and design in general and yes to the problem.

From what I can make out your mistake you probably must be: inserir a descrição da imagem aqui

You can avoid this by using the properties of the controls after the method InitializeComponents(), because in it is where the components of the Form are: inserir a descrição da imagem aqui

Another alternative is to make the modifications in EventLoad: inserir a descrição da imagem aqui

To know what happens in the method InitializeComponent(), you can give two click on the file FormN.Designer.cs: inserir a descrição da imagem aqui

0

Should the panel3 and panel4 variables reference instances of the Calculator_panel object, reference elements belonging to the Calculator_panel or what other class? You have not declared the initialization of objects in any part of the posted code, so you cannot assign value to the attributes of them. 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 problem and post the rest of your code so we can solve the problem.

  • I am very beginner, when the program opens I want the panel3 and 4 to be invisible, when you click the panel4 button and the calculator panel is invisible

Browser other questions tagged

You are not signed in. Login or sign up in order to post.