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

set RadRibbonBarGroup width in code

3 Answers 316 Views
RibbonBar
This is a migrated thread and some comments may be shown as answers.
William Higgins
Top achievements
Rank 2
William Higgins asked on 07 Apr 2011, 03:38 AM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 12 Apr 2011, 04:16 PM
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
0
Nino
Top achievements
Rank 1
answered on 06 Jul 2014, 09:08 AM
Is there any way to make a group fill the remaining space in the bar ? Usually a Spring Property?
0
Ivan Todorov
Telerik team
answered on 10 Jul 2014, 07:27 AM
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.
 
Tags
RibbonBar
Asked by
William Higgins
Top achievements
Rank 2
Answers by
Ivan Todorov
Telerik team
Nino
Top achievements
Rank 1
Share this question
or