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

RadMenu autosize problem

1 Answer 245 Views
Menu
This is a migrated thread and some comments may be shown as answers.
GIJO JOSEPH
Top achievements
Rank 1
GIJO JOSEPH asked on 27 Jan 2011, 03:06 AM
I have a radmenu inside a user control. I had set the autosize=true and autosizemode=GrowAndShrink for the user control. For the RadMenu I had set autosize=true and Orientation=Horizontal. I am adding menu items dynamically. But the usercontrol that holds the RadMenu is not growing automatically and RadMenu grows into a second row. How can I make the usercontrol grow automatically as RadMenu add new Items horizontally. Please advice. Please see the attachment.

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 01 Feb 2011, 10:37 AM
Hello GIJO JOSEPH,

Thank you for writing.

The RadMenu is always fitting in the available size. If you set the AutoSize property of the user control to true, it will resize itself according the the controls in it, but the control in it (RadMenu) sizes itself according to its parent and you get the strange situation.

If you want to avoid this, you need to manually measure all the menu items and resize your user control. Here is the code to accomplish this:
Size size = new Size(0, 0);
RadMenuItem item = new RadMenuItem();
for (int i = 1; i < 6; i++)
{
    item = new RadMenuItem(("Item " + i));
    this.userControl1.RadMenu.Items.Add(item);
}
 
this.userControl1.RadMenu.LoadElementTree();
 
foreach (RadMenuItem menuItem in this.userControl1.RadMenu.Items)
{
    size.Width += menuItem.Size.Width + menuItem.Margin.Horizontal;
}
 
size.Width += this.userControl1.RadMenu.Padding.Horizontal + this.userControl1.Padding.Horizontal;
 
this.userControl1.Size = new Size(size.Width, userControl1.Height);

I hope this will help you out. If you have further need of assistance, I would be glad to provide it.

All the best,
Ivan Petrov
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
Menu
Asked by
GIJO JOSEPH
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or