RadLabel, WordWrap and TextAlignment

3 posts, 0 answers
  1. Marek
    Marek avatar
    48 posts
    Member since:
    Aug 2005

    Posted 23 Aug 2007 Link to this post

    The temporary fix that I have for the auto size problem for a label control has addressed one issue but raised another.  My label spans a number of lines of text and the word wrap feature (default?) is what I need.  However when I set TextAlignment to any of the left (or right) flavors (top-left, bottom-left etc.) I seem to get the top row left or right aligned, but the subsequent rows middle aligned based on the position of the first row. I hope this makes sense?  Is this a bug?

    Best regards

  2. Marek
    Marek avatar
    48 posts
    Member since:
    Aug 2005

    Posted 23 Aug 2007 Link to this post

    I'm now assuming that I should also be adding:

    RootElement.StringAlignment = StringAlignment.Near;

    Is this right?
  3. Angel
    Angel avatar
    121 posts

    Posted 24 Aug 2007 Link to this post

    Hello Marek,

    The solution you have found will work fine.

    Here is a short explanation why the label is acting the way you described. For RadLabel TextAlignment means alignment of the text primitive that is inside the control, not the way in which the text is painted. The functionality you need is controlled by the TextPrimitive and its property StringAlignment.

    Your code sets the same property to the root element and that property is propagated to the primitive. In order to see and manipulate the properties of TextPrimitive you must click "Edit UI elements" from the Action List of RadLabel and select the tree item that starts with "Text:".

    We agree that the behavior of RadLabel's TextAlignment is not obvious and differ from the behavior of Microsoft's Label. In one of the upcoming releases the label's API will be refactored in order to achieve more consistent behavior with other labels as well as to expose the rich painting functionality in a better way. Now the only way to have full control of TextPrimitive painting functionality is to access non-browsable property PaintTextFormat.

    For example, to disable painting of a line of text that is only partially visible you must use code like this:

    TextPrimitive primitive = (TextPrimitive)this.radLabel1.RootElement.Children[0].Children[2];
    primitive.PaintTextFormat.FormatFlags |= StringFormatFlags.LineLimit;

    which is not the easiest and most intuitive way.

    Kind regards,

    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top