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

BoxLayout and positioning

1 Answer 131 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
superold asked on 31 Jan 2009, 04:19 PM

I have a control which inherits from RadTextBox

The layout should be the following, (a textbox with a button on its side and a couple of labels) 
| TextElement TextElement                          | 
|_TextBox ________________________________|_Button_| 

Problem is I cannot get the textbox and button to lay out in the correct order. The button is always rendered to the left and the textbox to the right, any way to change this?

/ jorge

        protected override void CreateChildItems(RadElement parent) 
            title.Text = "Title"
            title.Class = "Title"
            validation.Text = "* Validation failed"
            validation.Visibility = ElementVisibility.Collapsed; 
            validation.Class = "Validation"
            validation.ForeColor = Color.Red; 
            AcceptsTab = false
            TabStop = true
            textBoxElement.Size = new Size(402, 20); 
            button.Image = global::revival.Properties.Resources.file_16; 
            button.ImageAlignment = System.Drawing.ContentAlignment.MiddleCenter; 
            button.TabIndex = 0; 
            button.Dock = DockStyle.Right; 
            button.ButtonElement.StretchHorizontally = false
            button.ButtonElement.StretchVertically = false
            button.ButtonElement.Margin = new Padding(4, 0, 0, 0); 
            button.ButtonElement.Padding = new Padding(1); 
            BoxLayout layoutTexts = new BoxLayout(); 
            layoutTexts.Orientation = Orientation.Horizontal; 
            layoutTexts.StretchVertically = false
            BoxLayout layoutEditor = new BoxLayout(); 
            layoutEditor.Orientation = Orientation.Horizontal; 
            layoutEditor.StretchVertically = false
// how do i get the textbox to render to the left and the button to the right? 
            BoxLayout layout = new BoxLayout(); 
            layout.Orientation = Orientation.Vertical; 
            Size = new Size(425, 34); 

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 02 Feb 2009, 03:58 PM
Hello Jorge Delgado-Lopez,

You should use the static method DockLayoutPanel.SetDock(RadElement element, Dock dock) to arrange element to the desired position.
DockLayout starts to arrange elements from Left To Right ,e.g. first added element will be arranged in most left position.

 DockLayoutPanel.SetDock(button.ButtonElement, Dock.Right); 
 DockLayoutPanel.SetDock(textBoxElement, Dock.Left); 
 layoutEditor.LastChildFill = true

Also look our StackLayoutPanel that is similar to DockLayout panel, without docking and LastChildFill property.

Please, instead of the RadButton.Button element use only ButtonElement, because in the first case the button element will be arranged from Button layout and second time from DockLayout.

I will be glad to help you further with this custom layout.

Sincerely yours,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question