The project sometimes does not recognize me a class

1

I have a class that I use to generate the custom buttons of my project in winforms, I simply define the font..color and in this way I use this custom button in all my forms.

The structure of files and directories that I have is this, within the solution I have this class

Content of the controls classCustomized

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace controlesPersonalizado
{
    public class botonColor : Button
    {
        private static event EventHandler ColorCambiado;
        private static Color fondo = Color.White;
        private static Color colorfuente = Color.Black;

        public static Color Fondo
        {
            get
            {
                return fondo;
            }
            set
            {
                fondo = value;
                if (ColorCambiado != null) ColorCambiado(null, EventArgs.Empty);
            }
        }

        public static Color ColorFuente
        {
            get
            {
                return colorfuente;
            }
            set
            {
                colorfuente = value;
                if (ColorCambiado != null) ColorCambiado(null, EventArgs.Empty);
            }
        }

        public botonColor()
        {
            Fondo = fondo;
            ColorFuente = colorfuente;

            this.BackColor = fondo;
            this.ForeColor = colorfuente;
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            ColorCambiado += botonColor_ColorCambiado;
        }


        private void botonColor_ColorCambiado(object sender, EventArgs e)
        {
            this.BackColor = fondo;
            this.ForeColor = colorfuente;
        }
    }

}

The problem I have is that sometimes (not always) when I open the form in design mode I get this error

I leave you some captures of the properties of the file

Sometimes recompiling the whole solution, closing the form and reopening it works but sometimes not. What can I do?

Thank you,

    
asked by ilernet 31.05.2017 в 12:46
source

2 answers

3

This is because you directly copied the file to the folder and what Visual Studio does is recognize that file but not as part of the project, to solve it you must follow the following steps:

  • Right click to the file
  • Inclusion in the project
  • Once this is done, Visual Studio will recognize it as part of the project and will not send you errors.

        
    answered by 31.05.2017 в 14:34
    1

    You should check the class namespace and import it correctly. many times deleting it and giving it add - > existing Item (outside of which you add it to the project) corrects the namespace (likewise validate it)

        
    answered by 02.06.2017 в 21:01