RadMenu autosize problem

2 posts, 0 answers
    GIJO JOSEPH avatar
    1 posts
    Member since:
    Dec 2009

    Posted 26 Jan 2011 Link to this post

    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.

  2. Ivan Petrov
    Ivan Petrov avatar
    701 posts

    Posted 01 Feb 2011 Link to this post

    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));
    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.
  3. DevCraft banner
Back to Top