Antonio Teh Sumtin
Antonio Teh Sumtin

Reputation: 498

C# Forms - Label text changing with click events

In C# forms application I have done the following:

Label Some; string S;
private void Something()
{
  Some.text = S;
  Some.Location = new Point(100, 100);
  Some.Size = new Size(300, 300);
  this.Controls.AddRange(new System.Windows.Forms.Control[] { Some });
}

Then I defined S with click events:

private void YARR_click(object sender, System.EventArgs e)
{
  S="Some random text";
}

And another:

private void HARR_click(object sender, System.EventArgs e)
{
  S="Some other random text";
}

Once created label "Some" does not change its text to value of "S" when I click those things... What am I missing?

Upvotes: 0

Views: 4305

Answers (2)

Ali
Ali

Reputation: 135

please change the label text not assign value to string.

do Some.text = "Some random Text" on click event or call Something() function in click event.

Upvotes: 0

vguzmanp
vguzmanp

Reputation: 825

If what you are clicking is in the same Form as the Label you want to change the text, you just have to do

private void YARR_click(object sender, System.EventArgs e)
{
  Some.Text="Some random text";
}

Upvotes: 2

Related Questions