I can’t find a resolution for that mistake

Asked

Viewed 939 times

-1

I have a C# program and it is giving MANY bugs different, I’ll send everyone here, as follows:

Code Error: Description:

So come on.

internal AcessoAdd()
{
    InitializeComponent();
}

Error: System.ComponentModel.Win32Exception: 'Error while creating window identifier.'

Correction: I changed from Ternal to Public

Description: this code was already there, I tried to format the PC as recommended, I tried to tinker with regedit and increase the amount of window identifiers allowed, but nothing helps.

UsuarioForm usuForm = new UsuarioForm();

Error: System.StackOverflowException

Description: Usuarioform as its name already says, is a form, I create a variable to then open it but this error happens and I’ve tried everything also to make it work.

For now that’s it, you’ll probably have more after you fix this one, but someone knows how to answer me these two?

User Code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Linq;
using System.Xml.Linq;
using System.Threading.Tasks;

namespace PecsCon
{
public partial class UsuarioForm
{

    public UsuarioAdd usuAdd = new UsuarioAdd();
    public AcessoAdd acAdd = new AcessoAdd();

    internal UsuarioForm()
    {
        InitializeComponent();
    }

    public string idgrid;
    public string funcidgrid;
    public string logingrid;
    public string senhagrid;
    public int deletadogrid;
    public int op;
    private void Usuario_Load(object sender, EventArgs e)
    {
        this.MdiParent = FormPrincipal.DefaultInstance;
        this.Dock = DockStyle.None;

        //variavel para utilizar a classe
        BancoUsuario bncusu = new BancoUsuario();

        rbTodos.Checked = true;
        //preenche o datagridview
        bncusu.PreencheDataGrid(DataGridViewUsu, op);



    }

    private void ButtonX4_Click(object sender, EventArgs e)
    {

        acAdd.Show();
        if (!string.IsNullOrEmpty(idgrid))
        {

            acAdd.cboxUsuario.SelectedValue = idgrid;

        }


    }

    private void usuCadastro_Click(object sender, EventArgs e)
    {

        usuAdd.add_update = 1;

        usuAdd.Show();


    }

    private void TextBox1_TextChanged(object sender, EventArgs e)
    {
        BancoUsuario bncusu = new BancoUsuario();

        bncusu.ProcuraTuplaUsu(ref DataGridViewUsu, procuraUsu, op);
    }

    private void rbDesativados_CheckedChanged(object sender, EventArgs e)
    {
        if (rbDesativados.Checked == true)
        {
            op = 2;


            //variavel para utilizar a classe
            BancoUsuario bncusu = new BancoUsuario();

            //preenche o datagridview
            bncusu.PreencheDataGrid(DataGridViewUsu, op);
        }
    }

    private void rbTodos_CheckedChanged(object sender, EventArgs e)
    {
        if (rbTodos.Checked == true)
        {
            op = 3;


            //variavel para utilizar a classe
            BancoUsuario bncusu = new BancoUsuario();

            //preenche o datagridview
            bncusu.PreencheDataGrid(DataGridViewUsu, op);
        }
    }

    private void rbAtivos_CheckedChanged(object sender, EventArgs e)
    {
        if (rbAtivos.Checked == true)
        {
            op = 1;


            //variavel para utilizar a classe
            BancoUsuario bncusu = new BancoUsuario();

            //preenche o datagridview
            bncusu.PreencheDataGrid(DataGridViewUsu, op);
        }
    }

    private void usuDeletar_Click(object sender, EventArgs e)
    {

        BancoUsuario bncusu = new BancoUsuario();

        bncusu.DeletaUsu(Convert.ToInt32(this.idgrid), op);

    }

    public void DataGridViewUsu_CellClick(object sender, DataGridViewCellEventArgs e)
    {

        if (e.RowIndex >= 0)
        {

            DataGridViewRow row = null;

            row = this.DataGridViewUsu.Rows[e.RowIndex];

            BancoUsuario bncusu = new BancoUsuario();



            idgrid = row.Cells["Id"].Value.ToString();
            funcidgrid = row.Cells["Id Funcionario"].Value.ToString();
            logingrid = row.Cells["Login"].Value.ToString();
            senhagrid = row.Cells["Senha"].Value.ToString();
            deletadogrid = Convert.ToInt32(row.Cells["Deletado"].Value);

        }

    }

    private void usuVizualizar_Click(object sender, EventArgs e)
    {

        BancoUsuario bncusu = new BancoUsuario();

        usuAdd.add_update = 2;

        bncusu.buscaUsu(Convert.ToInt32(idgrid), Convert.ToInt32(funcidgrid), ref logingrid, ref senhagrid, ref deletadogrid, ref usuAdd.NomeComboBox, ref usuAdd.loginText, ref usuAdd.senhaText, usuAdd.cbAtivo.Checked);

    }
}

}

  • Only with this code there is no help. It would be nice [Edit] and put the code UsuarioForm also.

  • I will edit now.

  • creation of variable "Accessed acAdd = new Accessed();"

2 answers

1

Check if you are importing the namespaces.

The classes User and Acessoadd both are in a different namespaces than the Pecscon.

If, for example, they are in a namespces called Users and Accesses respectively, try this:

    using NomeDoProjeto.Usuarios;
    using NomeDoProjeto.Acessos;
  • The only thing that appeared here is "using Pecscon.My;" and "using Pecscon,Properties", both are in the Pecscon namespace

  • The Accessoadd and Usuarioadd classes are within these namespaces?

  • Users and Accessoadd are in the Pecscon namespace

  • 1

    I fixed the first bug, I switched from "Internal Acessoadd()" ... to "Public Acessoadd()..."

  • What’s the other mistake?

  • the second that is in the question, I corrected agr missing the error that is giving in Usuarioform usuForm = new Usuarioform(), the System error.Stackoverflowexception

  • Post the classes Usuarioadd and Acessoadd that as you said, are in the same namespace.

Show 2 more comments

0

remove

internal UsuarioForm()

place

public  UsuarioForm()

Browser other questions tagged

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