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
40
ButtonTool Sizing on Ribbon
posted

I am trying to duplicate the Clipboard group within Word 2007's ribbon menu in my application.  It will have a large paste ButtonTool and small ButtonTool for cut and copy.  The entire ribbon (tabs, groups and tools) will be built programatically rather than with the designer.  I am having trouble getting the paste button to show up larger.  Listed below are the properties that I have set to try and accomplish this:

pasteButtonTool.InstanceProps.PreferredSizeOnRibbon = INFRATOOLBAR.RibbonToolSize.Large;
pasteButtonTool.SharedProps.AppearancesLarge.Appearance.Image = Paste32x32;
pasteButtonTool.SharedProps.Caption = "Paste";

I have examined the way it is accomplished when using the designer (in the code spit), and for some reason it creates 2 instances of a ButtonTool.  Is that the only way to get that to work?  There should be a way to make this happen without 2 ButtonTool objects.

 

thank-you 

Parents
  • 44743
    Verified Answer
    posted

    firstdata said:

    I am having trouble getting the paste button to show up larger.  Listed below are the properties that I have set to try and accomplish this:

    pasteButtonTool.InstanceProps.PreferredSizeOnRibbon = INFRATOOLBAR.RibbonToolSize.Large;
    pasteButtonTool.SharedProps.AppearancesLarge.Appearance.Image = Paste32x32;
    pasteButtonTool.SharedProps.Caption = "Paste";

    The ribbon is probably resizing the paste button tool to a smaller size due to a lack of space. You can prevent this by setting the MinimumSizeOnRibbon to Large as well.

    firstdata said:

    I have examined the way it is accomplished when using the designer (in the code spit), and for some reason it creates 2 instances of a ButtonTool.  Is that the only way to get that to work?  There should be a way to make this happen without 2 ButtonTool objects.

    Yes and no. Internally, each tool you create must have a 'root' tool that keeps all shared properties and shows up in the run-time customize dialog, even if the tool is not present on the ribbon or any toolbars. If that tool is also displayed on a ribbon group, toolbar, or menu, an additional 'instance' tool must be created to keep the instance properties of that specific instance of the tool being displayed. This is because the same tool can have a different caption, icon, preferred size on ribbon, ... in different places.  So in your designer code, the 'root' tool is created and added to the toolbars manager's Tools collection. Then the 'instance' tool is created and added to the ribbon group's Tools collection. However, you don't need to create the instance tool. You can have the toolbars manager create it for you:

    ButtonTool pasteButtonRootTool = new ButtonTool("Paste");

    pasteButtonRootTool.SharedProps.AppearancesLarge.Appearance.Image = Paste32x32;

    pasteButtonRootTool.SharedProps.Caption = "Paste";

    this.ultraToolbarsManager.Tools.Add(pasteButtonRootTool);

    ButtonTool pasteButtonInstanceTool = this.ultraToolbarsManager.Ribbon.Tabs[0].Groups[0].Tools.AddTool("Paste");

    pasteButtonInstanceTool.InstanceProps.MinimumSizeOnRibbon = INFRATOOLBAR.RibbonToolSize.Large;

     

Reply Children