Autosizing a RadTextBoxElement to its text

2 posts, 1 answers
  1. Michael
    Michael avatar
    33 posts
    Member since:
    Mar 2009

    Posted 02 Apr 2009 Link to this post

    Hello -

    I'm trying to cause a RadTextBoxElement to automatically size to its text, similar to the way a TextPrimitive automatically sizes to its text.  Here is the code snippet:

            public Form1() 
                StackLayoutPanel panel = new StackLayoutPanel(); 
                panel.Orientation = Orientation.Horizontal; 
                panel.AutoSize = true
                panel.Children.Add(new TextPrimitive() { Text = "Color:" }); 
                panel.Children.Add(new RadTextBoxElement() { Text = "Purple" }); 
                RadPanel elementsContainer = new RadPanel(); 
                elementsContainer.ThemeName = "Desert"

    The TextPrimitive properly sizes to its text ("Color:"), but the RadTextBoxElement fails to size to its text ("Purple").  If I set AutoSize = true on the RadTextBoxElement, nothing changes.  If I also set the AutoSizeMode to WrapAroundChildren, still no change.  Can you advise me on how to make this work?

    Michael Hewitt
    Precision Software Design, LLC
  2. Answer
    Mike avatar
    640 posts

    Posted 03 Apr 2009 Link to this post

    Hello Michael,

    RadTextBox (respectively RadTextBoxElement) control uses internally the standard TextBox control (mainly due to its complexity). This means RadTextBoxElement has the same limitations as TextBox.
    You can control whether the text box should appear on a single or multiple lines by settings the Multiline property (radTextBoxElement.TextBoxItem.Multiline)

    If you need to "autosize" the text box according to the text, you shoud set Multiline=true and set TextBoxElement size, corresponding to the measured text rectangle. You can use the library method:

    Let me know if this works for you.

    All the best,
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. DevCraft R3 2016 release webinar banner
Back to Top