Results 1 to 6 of 6
  1. Default Complete newb with C#


    I am creating a GUI with C#. I have a textbox, "ProductName", with ProductName.MaxLength set to 55 (this is for eBay). I want the user to be able to know how many characters they have left to work with. In essence I want this: a dynamic piece of text that shows "55 - len(ProductName)". I'm not very good with C# or XAML, so what do you guys recommend? How do I go about accomplishing this?

  2. Default


    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.

  3. Default


    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.

  4. Default


    Code:
    private void ProductName_TextChanged(object sender, TextChangedEventArgs e)
    {
        lblCharactersLeft.Content = (ProductName.MaxLength - ProductName.Text.Length).ToString();
    }
    Try this. Apparently in XAML, labels use .Content instead of .Text, and the event is TextChangedEventArgs e instead of a generic EventArgs e.

    What compiler/editor are you using, Fiel?

  5. Default


    MSVC# 2008 Express.

    Is WinForms that much easier to use? I wouldn't know

  6. Default


    I don't know anything about WPF, like Spaz, except earlier when I checked how to do the above. I've just always used WinForms.

  7.  

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •