Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

c# - The variable 'variable_name' is either undeclared or was never assigned

I have a question related to the error on the title. Im working with c# and Visual Studio 2010.

I have a form declared as "public class FormularioGeneral : Form", which is the base for the rest of the forms in my application. When i try to access the Designer View i get this error several times, as you can see in the image:

Sample of errors All the errors references lines inside the InitializeComponent method, where the value is assigned to a property like this one:

[...]            
this.PanelMargenIzquierdoCapaBase.BackColor = m_ColorCapaBase;
[...]

But all the variables are declared in the same class as read-only properties and all of them are assigned inside a method which is called in the constructor.

Declaration of properties:

    protected Color m_VariableName;
    public Color VariableName
    {
        get { return m_VariableName; }
        set { }
    }

Constructor code:

    public FormularioGeneral()
    {
        ConfigurarUI();
        AccionesConstructor();
        InitializeComponent();
        PostInicializacionComponentes();
        EstablecerIcono();
        InicializarLocalizacionFormulario();
    }

ConfigurarUI method:

public virtual void ConfigurarUI()
{
        [...]

        m_AltoBordeSuperiorCapaBase = 30;
        m_AltoBordeInferiorCapaBase = 7;
        m_AnchoBordesLateralesCapaBase = 7;

        m_ColorCapaBase = Color.FromArgb(50, 100, 150);
        m_ColorTextoCapaBase = Color.White;
        m_ColorTextoBotonAplicacion = Color.Black;

        m_FuenteTextoIzquierdoCapaBase = new System.Drawing.Font("Verdana", 11.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        m_FuenteTextoCentroCapaBase = new System.Drawing.Font("Verdana", 14.0F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        [...]
}

So, as far as i know, all the variable which are giving the errors are correctly declared and have a value assigned before the InitilizeComponent function is called.

Im stuck at this point and dont know what to do to solve the problem. Hope some of you can help me with this issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So, I have had the same problem in the past, for fix I did the following:

  • Solution → Clean Solution;
  • Build → Rebuild Solution;
  • Close Visual Studio, re-open.

Thanks a lot to Marshall Belew!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...