set RadRibbonBarGroup width in code

4 posts, 1 answers
  1. William Higgins
    William Higgins avatar
    8 posts
    Member since:
    Jul 2009

    Posted 06 Apr 2011 Link to this post

    Hello,

    I am in need of setting the width of a RadRibbonBarGroup in my code and when I assign an integer value to it I get the following error.
    Expression is a value and therefore cannot be the target of an assignment.

    Here is the code I am using to assign the width value.
    Me.RadRibbonBarGroup1.Size.Width = 1000

    I am using the latest winforms controls.  Q1 2011

    Any help would be appreciated greatly.
    Thanks in advance.
  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 12 Apr 2011 Link to this post

    Hi William Higgins,

    You are getting this error because Size is a value type (not a reference one) and therefore setting its width won't have any effect.

    In order to change the width of the ribbon group you can change its MinSize property:

    Me.RadRibbonBarGroup1.MinSize = New Size(1000,0)

    If you want to use the Size property, you must also set the AutoSize property to false. When AutoSize is set to true, the size of the element is determined by the control that contains it, depending on the available space and its layout.

    Me.RadRibbonBarGroup1.AutoSize = False
    Me.RadRibbonBarGroup1.Size = New Size(100, Me.RadRibbonBarGroup1.Size.Height)

    In this approach you might have problems with determining the height, so I suggest using the MinSize property as a clearer way.

    I hope you find this useful. If you have any additional questions, feel free to ask.

    Greetings,
    Ivan Todorov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nino
    Nino avatar
    9 posts
    Member since:
    Apr 2013

    Posted 06 Jul 2014 in reply to Ivan Todorov Link to this post

    Is there any way to make a group fill the remaining space in the bar ? Usually a Spring Property?
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 10 Jul 2014 Link to this post

    Hi Nino,

    Thank you for writing.

    There is no Spring property for the ribbon groups but you can achieve this by adjusting their MinSize property when form changes its size. Note that in order for this to work you would need to disable collapsing the groups by setting their AllowCollapsed property. The following code snippet demonstrates this:
    public Form1()
    {
        InitializeComponent();
        this.SizeChanged += Form1_SizeChanged;
     
        foreach(RibbonTab tab in this.radRibbonBar1.CommandTabs)
        {
            foreach(RadRibbonBarGroup group in tab.Items)
            {
                group.AllowCollapsed = false;
            }
        }
    }
     
    protected override void OnShown(EventArgs e)
    {
        base.OnShown(e);
        AdjustLastGroupMinSize();
    }
     
    void Form1_SizeChanged(object sender, EventArgs e)
    {
        AdjustLastGroupMinSize();
    }
     
    void AdjustLastGroupMinSize()
    {
        RadRibbonBarGroup lastGroup = this.radRibbonBar1.SelectedCommandTab.Items[this.radRibbonBar1.SelectedCommandTab.Items.Count - 1] as RadRibbonBarGroup;
        lastGroup.MinSize = new Size(this.radRibbonBar1.Width - lastGroup.ControlBoundingRectangle.Left - 10, lastGroup.MinSize.Height);
    }

    Hope this will help.

    Regards,
    Ivan Todorov
    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