0

I have a user control which assembles a string based on two text fields (first name and last name) and I'd like to have another label use this to say something like "Your name is FIRSTNAME LASTNAME".

Although I can see the public string the user control outputs, I can't find an event which specifies when the user control has new inputs.

It'd be great if I could do something like...

    private void userControl_Update()
    {
        lblYourName.Text = String.Format("Your name is {0}", userControl.name);
    }

But I have no idea how to do this.

I use VB2012 with visual c# and forms.

Thanks for any help.

Coat
  • 697
  • 7
  • 18
  • Are you using WinForms, Asp.Net, WPF, Silverlight? – Jason Down Sep 17 '13 at 00:24
  • I don't think you can do that if the user control has not exposed an event for you to subscribe to. That is unless you have the source code for the user control and are able to add the event yourself. – Jason Down Sep 17 '13 at 01:20
  • The user control is my own so I do have the source code. How could I go about adding the event? – Coat Sep 17 '13 at 01:27
  • Take a look at this question: http://stackoverflow.com/questions/2188059/winforms-user-controls-custom-events – Jason Down Sep 17 '13 at 01:33
  • Glad to hear. Good luck! I'll vote to make this question a duplicate of that one then. – Jason Down Sep 17 '13 at 02:36

1 Answers1

1

It looks like you are using WinForms.

In that case, I believe the event you are looking for is the TextChanged event:

// Set using the visual Form Designer, generally
lblName.TextChanged += lblName_TextChanged;

// Later, the event handler
private void lblName_TextChanged(object sender, EventArgs e)
{
    lblYourName.Text = String.Format("Your name is {0}", lblName.Text);
}
Matt Dillard
  • 14,677
  • 7
  • 51
  • 61
  • My mistake. In the original question I implied that I wanted to grab the information off a label when really it's a custom user control with a custom field that I want. I've updated the question now. – Coat Sep 17 '13 at 00:39