1
Answer

How to Change Label Text

Ask a question
Developer

Developer

13y
2.9k
1

Hi,

In my windows form i have a label and a button. Initially that label will be having some text. On click even of the button i will invoice a function written in different class, in that function i want to change the text of that label.

My Code is

In Form1.cs

1. I have changed modifiers of label to public

private void button1_Click(object sender, EventArgs e)
        {
             //Call class1's static Method
            Class1.Test();
        }

In Class1.cs

 public static void Test()
        {
            //Creating the object of Form1
            Form1 abc = new Form1();
            //changing the label text
            abc.lblTest.Text = "Text Changed";
        }

By doing like this i am not able to change the text. What is the problem

Answers (1)