Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Complete newb with C#
#3
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
Code:
private void ProductName_TextChanged(object sender, EventArgs e)
{
    lblCharactersLeft.Text = (ProductName.MaxLength - ProductName.Text.Length).ToString();
}
This will execute any time the text is changed, hence the TextChanged, so it will automatically update the number.

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.
Reply


Messages In This Thread
Complete newb with C# - by Fiel - 2009-10-18, 06:32 PM
Complete newb with C# - by JoeTang - 2009-10-18, 09:50 PM
Complete newb with C# - by Spaz - 2009-10-18, 10:58 PM
Complete newb with C# - by JoeTang - 2009-10-18, 11:34 PM
Complete newb with C# - by Fiel - 2009-10-19, 07:15 AM
Complete newb with C# - by JoeTang - 2009-10-19, 08:05 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)