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

CommandBarTextBox; Dynamic width by content

1 Answer 154 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
Raoul
Top achievements
Rank 1
Raoul asked on 22 Feb 2013, 10:25 PM
I have a RadCommandBar docked (to the bottom). It contains 2 labels and 2 textboxes with 1 seperataror. Its 'RightToLeft' property is set to true. It looks something like this:

-------------------------------------------|---------------------------
              label1   [ TextBox1 ]   |   label2   [ TextBox2  ]
-------------------------------------------|---------------------------

I'd like to make the width of TextBox1 depending on it's contents. E.g. when it contains "short" the width is 100px, but when "a somewhat longer text" is displayed e.g. 400px. The textboxes are readonly.

The properties "AutoSize" and "AutoSizeMode" of the  RadCommandBar, CommandBarRowElement, CommandBarStripElement and CommandBarTextBox elements are set to True and Auto. The textbox doesn't resize when the textcontent changes?

How can I obtain this functionality?

Kind regards,
Raoul

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 26 Feb 2013, 03:07 PM
Hello Raoul,

Thank you for writing.

CommandBarTextBox/RadTextBox are editable controls and this is why they does not support re-sizing. By design, the editable controls does not have this option. 
However you can re-size manually the control on TextChanged event. For example:
this.commandBarTextBox1.TextChanged += new System.EventHandler(this.commandBarTextBox1_TextChanged);
 
 private void commandBarTextBox1_TextChanged(object sender, EventArgs e)
 {
     CommandBarTextBox textBoxElement = ((RadTextBoxItem)sender).FindAncestor<CommandBarTextBox>();
     Size textSize = TextRenderer.MeasureText(textBoxElement.Text, textBoxElement.Font);
 
     textBoxElement.MinSize = new Size(textSize.Width, 22);
 }

I hope this helps.

Kind regards,
Peter
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
CommandBar
Asked by
Raoul
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or