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,
>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