This is a migrated thread and some comments may be shown as answers.

Autosizing a RadTextBoxElement to its text

1 Answer 218 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Michael asked on 02 Apr 2009, 09:44 PM
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

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 03 Apr 2009, 03:22 PM
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.
General Discussions
Asked by
Top achievements
Rank 2
Answers by
Telerik team
Share this question