Reading text from label

Martin

I have just a little problem with reading text from label, but...

I have two forms. Form_1, and Form_2.

Form_1 is sending (on demand) text from "label_one" directly to "label_two" in Form_2.

But in Form_2 i have another label called "label_reader" that need to show any changes done in "label_two" text.

I must (dynamically?) read any changes from "label_two" and show it in label_reader.

Never had a similar problem, and have no idea how to do that. It can't be done with the use of a button.

Any help will be greatly appreciated!

René Vogt

You can use the TextChanged event of label_two. Subscribe to that event (most likely in the constructor of your Form_2) and set the text of label_reader when the event is raised:

public partial class Form_2 : Form
{
   //...

   public Form_2()
   {
       InitializeComponent();
       // your other code

       label_two.TextChanged += label_two_TextChanged;
   }

   // the event handler
   private void label_two_TextChanged(object sender, EventArgs e)
   {
       label_reader.Text = label_two.Text; // or what ever you want to do
   }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related