C#
C#

help

Root Question Message

Nikolaaa
Nikolaaa10/17/2022
cant change text label inside events?

why is scorelbl.Text red when I have label named like that in designer?
MonJamp
MonJamp10/17/2022
Can you post the error message?
MonJamp
MonJamp10/17/2022
Also is this WinForms, WPF, MAUI?
Nikolaaa
Nikolaaa10/17/2022
winforms
Nikolaaa
Nikolaaa10/17/2022
it says it does not exist in current context
Nikolaaa
Nikolaaa10/17/2022
i think it was working in net framework when i used it now i use net core
MonJamp
MonJamp10/17/2022
It could be a typo, are you sure it's named exactly scorelbl in the designer (no capitals)?
Nikolaaa
Nikolaaa10/17/2022
yes i checked that already
Nikolaaa
Nikolaaa10/17/2022
also i think this was not happening until i updated vs
MonJamp
MonJamp10/17/2022
Are you able to compile it? Sometimes there's red squiggles where there shouldn't be
Nikolaaa
Nikolaaa10/17/2022
umm i didnt try i will now
Nikolaaa
Nikolaaa10/17/2022
should have i put everything in
public Snek()
{
InitializeComponent();


}
Nikolaaa
Nikolaaa10/17/2022
?
Nikolaaa
Nikolaaa10/17/2022
or it can be outside
MonJamp
MonJamp10/17/2022
Snek() is the constructor method for the class. scorelbl should be accessible anywhere within the class
MonJamp
MonJamp10/17/2022
Can you post the entire class? Afaik it should be working
Nikolaaa
Nikolaaa10/17/2022
still red
Nikolaaa
Nikolaaa10/17/2022
i also change names
Nikolaaa
Nikolaaa10/17/2022
his scoretxt is my scorelbl but it is red
Nikolaaa
Nikolaaa10/17/2022
and see in tutorial its outside public Form1()
Nikolaaa
Nikolaaa10/17/2022
could it be a problem that he may be using net framework and I use net core
MonJamp
MonJamp10/17/2022
Yes it's outside the constructor but still within the Form1 class. Can you post your code for Form1?
MonJamp
MonJamp10/17/2022
I doubt it. I've written WinForms applications that work fine once migrated from Framework to Core. For an application like this, it shouldn't matter that it's Framework or Core
MonJamp
MonJamp10/17/2022
Also a screenshot of the properties of the control itself would be useful
Nikolaaa
Nikolaaa10/17/2022
one sec
Nikolaaa
Nikolaaa10/17/2022
do you want only the part where the name is or?
Nikolaaa
Nikolaaa10/17/2022
Nikolaaa
Nikolaaa10/17/2022
its identical to his but with Snek instead of Form1
Nikolaaa
Nikolaaa10/17/2022
and scorelbl instead of scoretxt
MonJamp
MonJamp10/17/2022
Do you get any other errors or is this the only error you get when you compile?
MonJamp
MonJamp10/17/2022
The information I'm still missing is that, I still don't know if scorelbl is in the same class as Snek. Do you see the file named Snek.designer.cs?
Nikolaaa
Nikolaaa10/17/2022
i didnt yet compile cus i need to change other things to meet my names
Nikolaaa
Nikolaaa10/17/2022
yes
Nikolaaa
Nikolaaa10/17/2022
namespace Snek
{
    partial class Snek
    {
        /// <summary>
        ///  Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        ///  Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        ///  Required method for Designer support - do not modify
        ///  the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 450);
            this.Text = "Form1";
        }

        #endregion
    }
}
Nikolaaa
Nikolaaa10/17/2022
this is from snek.designer.cs
MonJamp
MonJamp10/17/2022
The *.designer.cs file is autogenerated from the controls you add in the design view. In the file there should be a definition like Label scorelbl = new Label(); but that is absent from this file
MonJamp
MonJamp10/17/2022
IIRC it is generated during compile
Nikolaaa
Nikolaaa10/17/2022
you mean build?
Nikolaaa
Nikolaaa10/17/2022
or what
MonJamp
MonJamp10/17/2022
Fix the names and as many red squiggles as you can until you are ready to compile
MonJamp
MonJamp10/17/2022
Yes when you build the application, you are compiling the code
Nikolaaa
Nikolaaa10/17/2022
oh ok i will try
Nikolaaa
Nikolaaa10/17/2022
but wont the build fail if it has errors
Nikolaaa
Nikolaaa10/17/2022
i am fixing them but they are still red, but it doesnt matter right?
MonJamp
MonJamp10/17/2022
Sometimes the red squiggles you see when editing a code disappears when compiling it. This is especially true with WinForms since some files are autogenerated during compilation

Compiler error messages > editor error messages
Nikolaaa
Nikolaaa10/17/2022
also i am not sure which element is he using here where it says gameTimer.Stop that isnt normal label right?
Nikolaaa
Nikolaaa10/17/2022
im compiling
Nikolaaa
Nikolaaa10/17/2022
i commented the gametimer line until i know what it is
MonJamp
MonJamp10/17/2022
A good practice especially in GUI development is to name controls with the abbreviation of the control type.

For example:
btnPlay or playBtn
This shows that this control is of type Button

gameTimer
This control can be assumed to be of type Timer
Nikolaaa
Nikolaaa10/17/2022
there is no Timer in toolbox
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy