2009-10-18, 10:58 PM
JoeTang Wrote:In the Designer Code:
this.ProductName.TextChanged += new System.EventHandler(this.ProductName_TextChanged);
Generally, you can automatically achieve this by double clicking the object in the GUI, and it will create the code for you in both the Designer and the Form.
The form code should look like
This will execute any time the text is changed, hence the TextChanged, so it will automatically update the number.Code:private void ProductName_TextChanged(object sender, EventArgs e)
{
lblCharactersLeft.Text = (ProductName.MaxLength - ProductName.Text.Length).ToString();
}
Fiel mentioned XAML, so I assume he's using WPF and not WinForms. For WinForms, Joe's correct. I have no idea how to do it in WPF, I've never used WPF. Double-clicking the text box in the designer would be a good place to start though.

