Align Elements to right side of Commandbar

7 posts, 0 answers
  1. John Savold
    John Savold avatar
    2 posts
    Member since:
    Nov 2009

    Posted 10 May 2011 Link to this post

    I have a Commandbar with a stripelement that is stretched horizontaly across my form. I would like to add a label and a button and have the label aligned to the left and the button aligned to the right side of the Command bar. How can I accomplish this?
    Thanks.
  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 13 May 2011 Link to this post

    Hi John,

    Thank you for writing.

    To achieve the desired behavior, add to your strip element a label and a button. Then set the label StretchHorizontally property to true and TextAlignment to MiddleLeft:
    commandBarLabel1.StretchHorizontally = true;
    commandBarLabel1.TextAlignment = ContentAlignment.MiddleLeft;

    This should give you the desired layout. Should you have any other questions, do not hesitate to contact us.

    Greetings,
    Stefan
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Craig
    Craig avatar
    6 posts
    Member since:
    Mar 2014

    Posted 20 Sep in reply to Stefan Link to this post

    I'm trying to accomplish the same thing with the latest version of Telerik and Stefan's solution doesn't work. Any other suggestions?

     

    Craig

  5. Craig
    Craig avatar
    6 posts
    Member since:
    Mar 2014

    Posted 21 Sep in reply to Craig Link to this post

    I just realized that what I'm trying to do is a little different than the OP. I have a CommandBar with multiple strips. I would like the first strip to be right aligned and the rest to be left aligned. (Basically I need the equivalent of a spring between the first strip and the rest.)
  6. Craig
    Craig avatar
    6 posts
    Member since:
    Mar 2014

    Posted 21 Sep in reply to Craig Link to this post

    Sorry...first strip should be left aligned and the rest should be right aligned!
  7. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 Sep Link to this post

    Hello Craig,

    Thank you for writing.  

    In order to align the CommandBarStripElement you can use the RadCommandBarStripElement.DesiredLocation property. Note that when the RadCommandBar is resized it is necessary to adjust the DesiredLocation accordingly. Here is a sample approach:
    public Form1()
    {
        InitializeComponent();
     
        this.radCommandBar1.SizeChanged += radCommandBar1_SizeChanged;
        this.commandBarStripElement2.DesiredLocation = new PointF(this.radCommandBar1.Width -
            this.commandBarStripElement2.Size.Width, this.commandBarStripElement2.Location.Y);
    }
     
    private void radCommandBar1_SizeChanged(object sender, EventArgs e)
    {
        this.commandBarStripElement2.DesiredLocation = new PointF(this.radCommandBar1.Width -
            this.commandBarStripElement2.Size.Width, this.commandBarStripElement2.Location.Y);
    }

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  8. Craig
    Craig avatar
    6 posts
    Member since:
    Mar 2014

    Posted 23 Sep in reply to Dess Link to this post

    Thanks, Dess...this works perfectly.
Back to Top
UI for WinForms is Visual Studio 2017 Ready