locked
Auto ellipses function RRS feed

  • Question

  • I have a label. The label autosize set to false.

    If the string larger than the label size, truncate and add the ellipses.

    Like .net 2.0 have the auto ellipses property in label.

    Example:  Initially Label width is 40 px.

    The string length is 60 characters. Then compare the string length and size and do the action accordingly.

    string displayText = string.Empty;

    if((this.baseText.Length * this.Font.Size) > this.Width)

    {

    displayText = this.baseText.Substring (0, Convert.ToInt32(this.Width / this.Font.Size));

    base.Text = displayText + UIConstants.ELLIPSIS;

    }

    else

    {base.Text = this.baseText;}

    Please correct this function.

    Friday, December 9, 2005 11:47 AM

Answers

  • Hi,

    You can take advantage of the PrefferedWidth and PrefferedHeight of the label control to see if the text really fits the size of your label. Just compare it with the current width and height of your text...





    cheers,

    Paul June A. Domag
    Friday, December 9, 2005 2:50 PM

All replies

  • Hi,

    You can take advantage of the PrefferedWidth and PrefferedHeight of the label control to see if the text really fits the size of your label. Just compare it with the current width and height of your text...





    cheers,

    Paul June A. Domag
    Friday, December 9, 2005 2:50 PM
  • Right. First i can check the preferredwidth > label width, then assign the value with ellipse. My question is how to calculate how many characters will fit into the preferred width of the label.
    Monday, December 12, 2005 12:09 PM