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
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";
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:
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;
Thank you for your reply Mike. Is there a way to accomplish this without the use of a "Root" ButtonTool? I have acheived the desired look with the smaller ButtonTools (without the creation of a root ButtonTool) but not the large one. In my first post I failed to mention that not only is the button not showing up large, but the image is not showing either.
"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."
There where only a few tools on the tab to begin with... so I don't know if that would have been the case. Setting MinimumSizeOnRibbon to Large doesn't seem to work either.
"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;"
I tried to use your code also... I'm not sure if I have an older version or maybe missing a hot-fix because the compiler required me to cast the Group.AddTool method back to a ButtonTool... even though it is suppose to return a ToolBase.
firstdata said:Is there a way to accomplish this without the use of a "Root" ButtonTool? I have acheived the desired look with the smaller ButtonTools (without the creation of a root ButtonTool) but not the large one. In my first post I failed to mention that not only is the button not showing up large, but the image is not showing either.
Yes and no again: There is no way to not use a root tool. But if you add a tool instance to a toolbar, menu, or ribbon group, without a corresponding root tool being in the toolbars manager, I believe a root tool will be cloned from the tool added, so even though you are not specifying a root tool, one is used internally.
My guess is you created the ButtonTool instance with the constructor and passed it to the Add method of the RibbonGroup's tools collection. The problem with this is if the toolbars manager is not between BeginInit()...EndInit() calls, it assumes it is currently displaying and it clones the tools passed into the Add method. So the tool displayed in the toolbars manager is not the tool you created with the constructor and set properties on. Use the code I posted instead and set the display properties on the tool returned in the AddTool method. That is the actual tool instance being displayed in the ribbon.
firstdata said: I tried to use your code also... I'm not sure if I have an older version or maybe missing a hot-fix because the compiler required me to cast the Group.AddTool method back to a ButtonTool... even though it is suppose to return a ToolBase.
Sorry, that was my mistake. I just typed the code manually and didn't try to compile it. You do need to cast back to a ButtonTool.
I am having the problem with setting the "ButtonTool.InstanceProps.PreferredSizeOnRibbon = " on the fly. there is a drop down in the Toolbar that lets the user decide the style they want - Image, Large/Small or text only but everytime I try set the property above an object error occurs "Obj ref not set to an instance of an object" - its nothing. Tools are already set in the designer side of things not in code - images and captions.
Code sample:
For Each myToolBase As Infragistics.Win.UltraWinToolbars.ToolBase In Me.uToolbarsManager.Tools
myToolBase.InstanceProps.PreferredSizeOnRibbon = Infragistics.Win.UltraWinToolbars.RibbonToolSize.ImageOnly
Next
Is there another way to get to the InstanceProps? Should I use the RootTool method?
Any help would be much appreciated!
The problem here is you are iterating the root tools of the toolbars manager. They do not have InstanceProps because they are not instance tools, so getting their InstanceProps returns null. You should instead iterate the instance tools of the ribbon:
For Each tab as RibbonTab in Me.UltraToolbarsManager1.Ribbon.Tabs For Each group as RibbonGroup in tab.Groups For Each tool as ToolBase in group.Tools tool.InstanceProps.PreferredSizeOnRibbon = .RibbonToolSize.ImageOnly Next NextNext