Anchor radLabelElements in radStatusStrip.

8 posts, 1 answers
  1. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 12 Feb 2013 Link to this post

    I have two radLabelElements in my radStatusStrip.  I want one to be anchored to the left and the second anchored to the right.  I want the right one to use all of the space not used by the left one.
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 15 Feb 2013 Link to this post

    Hi Kipp,

    Thank you for writing.

    If you are using design time to add your labels, you can set the Spring property of the second label to make it fill the rest of the space. Alternatively, if you are using code, you should use the SetSpring method of the control. Here is an example:
    RadLabelElement leftLabel = new RadLabelElement();
    leftLabel.LabelFill.BackColor = Color.Yellow;
    leftLabel.LabelFill.GradientStyle = GradientStyles.Solid;
    leftLabel.Text = "I am the left label";
    radStatusStrip1.Items.Add(leftLabel);
     
    RadLabelElement rightLabel = new RadLabelElement();
    rightLabel.LabelFill.BackColor = Color.Red;
    rightLabel.LabelFill.GradientStyle = GradientStyles.Solid;
    rightLabel.Text = "I am the right label, and I am taking the rest of the space";
    radStatusStrip1.Items.Add(rightLabel);
     
    //make the label take the rest of the space
    radStatusStrip1.SetSpring(rightLabel, true);

    I hope this helps. 

    Regards,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 15 Feb 2013 Link to this post

    Doesn't work for me.  See attached.
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 20 Feb 2013 Link to this post

    Hello Kipp,

    This code works just fine on my end - please refer to the attached video. The video opens in browser and requires Shockwave flash player to play.

    If you continue experiencing issues, I assume that something in your project causing this behavior so please open new support ticket where you can attach it. Once we get it, we will investigate the reasons causing this behavior and will get back to you with the result.

    All the best,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  6. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 20 Feb 2013 Link to this post

    I threw together a project with a RadRibbonForm as is in my project.  The code does work as it is supposed to, so it is something in my project that is causing it to not behave as desired.  I'll go deeper and see what I can find.
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Feb 2013 Link to this post

    All right. Let me know if I can assist you, once you get to a reproducible scenario.
     
    Regards,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  8. Wayne
    Wayne avatar
    36 posts
    Member since:
    May 2013

    Posted 17 Sep 2014 in reply to Stefan Link to this post

    Sorry to reply to such and old post, but it's relevant to this topic and I'm sure it is worth answering here...

    What if the text in the left label exceeds the form?  In my case it pushes the right label out of view.  How would one fix the right label to always be there no matter the width of the left label?  Maybe add an ellipsis into the left label as well when it happens...
  9. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Sep 2014 Link to this post

    Hi Wayne,

    To achieve such a scenario, the easiest way would be to add a RadLabel control in the Controls collection of RadStatusStrip and dock it to the right side. In addition, you should set Margin to the container holding the items in RadStatusStrip. Here is a sample implementation:
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        InitializeComponent();
     
        RadLabelElement leftLabel = new RadLabelElement();
        leftLabel.LabelFill.BackColor = Color.Yellow;
        leftLabel.LabelFill.GradientStyle = GradientStyles.Solid;
        leftLabel.Text = "I am the left label";
        radStatusStrip1.Items.Add(leftLabel);
     
        RadLabel rightLabel = new RadLabel();
        rightLabel.Dock = DockStyle.Right;
        rightLabel.LabelElement.Margin = new System.Windows.Forms.Padding(0, 3, 0, 0);
        rightLabel.LabelElement.LabelFill.BackColor = Color.Red;
        rightLabel.LabelElement.LabelFill.GradientStyle = GradientStyles.Solid;
        rightLabel.Text = "I am the right label, and I am taking the rest of the space";
        radStatusStrip1.Controls.Add(rightLabel);
     
        radStatusStrip1.StatusBarElement.Items.Owner.Margin = new Padding(0, 0, rightLabel.Size.Width, 0);
     
    }
     
    void leftLabel_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "Bounds")
        {
            RadLabel rightLabel = (RadLabel)sender;
            radStatusStrip1.StatusBarElement.Items.Owner.Margin = new Padding(0, 0, rightLabel.Size.Width, 0);
        }
    }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready