Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Object doesn't contain a definition for "Text"

So I just learned Microsoft Visual. I tried to use label and trying to set a text using the event handler, but i got an error in the line this.lblText.Text, more specifically in the "Text", could someone please let me know how to solve it? I don’t really understand about C#

this is the code

namespace Praktikum1
{
    public partial class Form1 : Form
    {
        private object lblText;

        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.lblText.Text = "Belajar Pemrograman Visual C#";

        }
    }
}

the error is in = this.lblText, the Text,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You see to have added lblText by hand here

 private object lblText;

if generated by the form designer it would be declared as

private Label lblText;

You say the ‘module’ did this, I dont know what that means. Also its impossible to know if lblText is really a label or not.

If it is then this will work

((Label)this.lblText).Text = "Belajar Pemrograman Visual C#";

ie – casting the object to the Label type

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading