BoxLayout and positioning

2 posts, 0 answers
  1. Jorge Delgado-Lopez
    Jorge Delgado-Lopez avatar
    82 posts
    Member since:
    Aug 2007

    Posted 31 Jan 2009 Link to this post


    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); 

  2. Peter
    Peter avatar
    1148 posts

    Posted 02 Feb 2009 Link to this post

    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.
Back to Top