How to add a button to a pre-existing tab on ribbon (C#)?

会有一股神秘感。 提交于 2019-12-05 15:43:53

问题


I've successfully created a new tab and put it next to the pre-existing ones. Then I realized that I'll only have one button on it, so it makes more sense (for now) to put it on the Home tab. Didn't really get that to work though.

I've tried to follow the guides and walk-troughs. I've got me an XML and changed its XML to the following.

<tabs>
  <!--<tab idMso="TabAddIns">-->
  <tab idMso="TabHome">
    <group id="group1" label="Hazaa!">
      <box id="box1" />
    </group>
  </tab>
</tabs>

When I run the project I get no changes to the UI, so I guess that either:

  1. the XML is not read at all,
  2. the name TabHome is wrong (at least for Outlook 2010),
  3. the attribute idMso is wrong (at least for Outlook 2010) or
  4. other/combination of any of the mentioned.

What can I do to alter the ribbon? (Outlook 2010/VSTO/VS 2010/.NET 4).


回答1:


The attribute idMso is correct, but the id for the tab you want is TabMail. You can find a packed set of Excel-files containing lists of Office 2010 control IDs on MSDN. Then, as mentioned in a comment to the question, your sample XML may be missing the customUI and ribbon-tags. (Disclaimer: I haven't customized the ribbon in Outlook, only Word, Excel and PowerPoint, but I would guess they work the same?)

Try something like the this:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab idMso="TabMail">
                <group id="group1" label="Hazaa!">
                    <box id="box1" />
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>



回答2:


If you just want a button to appear in an existing ribbon, in Visual Studio, here https://msdn.microsoft.com/en-us/library/bb608628.aspx#Anchor_2

in your case change the OfficeId to TabMail




回答3:


For people frustrated that none of the other answers seem to be working, go to the properties for the Ribbon itself and set the RibbonType to Microsoft.Outlook.Explorer (or whichever context[s] you want to see the control in). It's a crucial step that's easy to overlook.

Then follow the other instructions to set OfficeId to TabMail.

Additionally, Office 2016 Fluent Control Identifiers can be found here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=50745




回答4:


Edited. Sorry, gave a dnn link. You want office and you want c#.

Here's a StackOverflow answer in VBA... How to get Ribbon custom Tabs IDs?

AccessibleChildren _
            Lib "oleacc.dll" _
                (ByVal paccContainer As Object, _
                 ByVal iChildStart As Long, _
                 ByVal cChildren As Long, _
                       rgvarChildren As Variant, _
                       pcObtained As Long) _
            As Long

Which in C# translates to

[Lib "oleacc.dll"]
Long AccessibleChildren(object paccContainer, 
                        long iChildStart, 
                        long cChildren, 
                        object rgvarChildren, 
                        long pcObtained)...

I never tried it, so not sure it works.

From all other documentation, it seems you simply get the ribbon object, and in it iterate (with foreach) through all the children



来源:https://stackoverflow.com/questions/12489832/how-to-add-a-button-to-a-pre-existing-tab-on-ribbon-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!