Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Resizing Ribbon minimizer button
posted

Hello,

I am trying to resize the Ribbon minimizer button by using a creation filter, but the result not what I except.

The clickable area of the minimize button remains small and the drawing of the background is wrong.

How can I solve this problems?

I made a sample for demonstrating the problem.

public partial class TestForm : Form
    {
        [STAThread]
        static void Main()
        {
            Application.Run(new TestForm());
        }

        private Infragistics.Win.UltraWinToolbars.UltraToolbarsManager toolbarManager;
        public TestForm()
        {
            InitializeComponent();
            this.Size = new Size(600, 400);
        }


        public class CreationFilter : IUIElementCreationFilter
        {
            public bool BeforeCreateChildElements(UIElement parent)
            {
                return false;
            }

            public void AfterCreateChildElements(UIElement parent)
            {
                var minimizer = parent as ButtonToolUIElement;
                if (minimizer != null)
                {
                    int desiredWidth = 50;
                    if (minimizer.Rect.Width != desiredWidth)
                    {
                        int addedWidth = desiredWidth - minimizer.Rect.Width;
                        var rect = minimizer.Rect;
                        rect.Width += addedWidth;
                        rect.X -= addedWidth;
                        minimizer.Rect = rect;
                    }
                }
            }
        }

        private void TestForm_Load(object sender, EventArgs e)
        {
            toolbarManager = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager();
            toolbarManager.DockWithinContainer = this;
            toolbarManager.Style = ToolbarStyle.Office2010;
            toolbarManager.Office2007UICompatibility = false;
            toolbarManager.Ribbon.FileMenuStyle = FileMenuStyle.ApplicationMenu;
            toolbarManager.Ribbon.Visible = true;
            toolbarManager.CreationFilter = new CreationFilter();
        }
    }

  • 6158
    Suggested Answer
    Offline posted

    Hello Gabor,

    The ribbon pin button is actually an internal tool called the RibbonPinButtonTool which is parented to the RibbonTabItemToolbar. The issue you are encountering with your creation filter is most likely due to the UIElement for the RibbonTabItemToolbar not being large enough to display the larger button UIElement. Often in creation filters, when you try to make an item larger, you will need to rearrange and resize other parent or sibling UIElements. The easiest way to achieve the desired behavior of a larger pin button is to actually place another unused tool on the RibbonTabItemToolber and then remove it's UIElements with the creation filter. By doing this, the size of the UIElement for the RibbonTabItemToolbar will have already be increased by the UltraToolbarsManager to account for the unused tool, so you simply need to increase the size of the pin button's UIElement:

    private void Form1_Load(object sender, EventArgs e)

    {

    this.ultraToolbarsManager1.Tools.Add(new ButtonTool("Unused"));

    this.ultraToolbarsManager1.Ribbon.TabItemToolbar.Tools.AddTool("Unused");

    this.ultraToolbarsManager1.CreationFilter = this;

    }

    public void AfterCreateChildElements(UIElement parent)

    {

    ButtonToolUIElement buttonToolUIElement = parent as ButtonToolUIElement;

    if (buttonToolUIElement != null &&

    buttonToolUIElement.Tool.Key == "Unused")

    {

    buttonToolUIElement.Parent.ChildElements.Remove(buttonToolUIElement);

    }

    }

    public bool BeforeCreateChildElements(UIElement parent)

    {

    ButtonToolUIElement buttonToolUIElement = parent as ButtonToolUIElement;

    if (buttonToolUIElement != null &&

    buttonToolUIElement.Tool.GetType().Name == "RibbonPinButtonTool")

    {

    buttonToolUIElement.Rect = buttonToolUIElement.Parent.Rect;

    }

    return false;

    }

    Let me know if you have any questions.

    Thanks,

    Chris