Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Menu, Application Menu, Context Menu > RadMenu autosize problem

Not answered RadMenu autosize problem

Feed from this thread
  • GIJO JOSEPH avatar

    Posted on Jan 26, 2011 (permalink)

    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.

    Attached files

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Feb 1, 2011 (permalink)

    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.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Menu, Application Menu, Context Menu > RadMenu autosize problem
Related resources for "RadMenu autosize problem"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]