简体   繁体   English

如何在功能区(C#)上的预先存在的选项卡中添加按钮?

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

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. 然后我意识到我只有一个按钮,所以将它放在Home选项卡上更有意义(现在)。 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. 我给了我一个XML并将其XML更改为以下内容。

<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: 当我运行项目时,我没有对UI进行任何更改,所以我猜:

  1. the XML is not read at all, 根本没有读取XML,
  2. the name TabHome is wrong (at least for Outlook 2010), 名称TabHome是错误的(至少对于Outlook 2010),
  3. the attribute idMso is wrong (at least for Outlook 2010) or 属性idMso是错误的(至少对于Outlook 2010)或
  4. other/combination of any of the mentioned. 任何上述的其他/组合。

What can I do to alter the ribbon? 我该怎么做才能改变色带? (Outlook 2010/VSTO/VS 2010/.NET 4). (Outlook 2010 / VSTO / VS 2010 / .NET 4)。

The attribute idMso is correct, but the id for the tab you want is TabMail . 属性idMso是正确的,但您想要的选项卡的ID是TabMail You can find a packed set of Excel-files containing lists of Office 2010 control IDs on MSDN. 您可以在MSDN上找到包含Office 2010控件ID列表的一组打包的Excel文件 Then, as mentioned in a comment to the question, your sample XML may be missing the customUI and ribbon-tags. 然后,如对问题的评论中所述,您的示例XML可能缺少customUI和ribbon-tags。 (Disclaimer: I haven't customized the ribbon in Outlook, only Word, Excel and PowerPoint, but I would guess they work the same?) (免责声明:我没有在Outlook中定制功能区,只有Word,Excel和PowerPoint,但我猜它们的工作方式相同?)

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>

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 如果您只想在现有功能区中显示按钮,请在Visual Studio中访问https://msdn.microsoft.com/en-us/library/bb608628.aspx#Anchor_2

in your case change the OfficeId to TabMail 在您的情况下,将OfficeId更改为TabMail

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). 对于那些其他答案似乎都没有工作的人感到沮丧,请转到功能区本身的属性,并将RibbonType设置为Microsoft.Outlook.Explorer (或者您想要查看控件的任何上下文[s])。 It's a crucial step that's easy to overlook. 这是一个容易被忽视的关键步骤。

Then follow the other instructions to set OfficeId to TabMail . 然后按照其他说明将OfficeId设置为TabMail

Additionally, Office 2016 Fluent Control Identifiers can be found here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=50745 此外,可以在此处找到Office 2016 Fluent控件标识符: https//www.microsoft.com/en-us/download/confirmation.aspx?id = 50745

Edited. 编辑。 Sorry, gave a dnn link. 对不起,给了一个dnn链接。 You want office and you want c#. 你想要办公室,你想要c#。

Here's a StackOverflow answer in VBA... How to get Ribbon custom Tabs IDs? 这是VBA中的StackOverflow答案... 如何获取功能区自定义选项卡ID?

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 在C#中转换为

[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 从所有其他文档中,您似乎只需获取功能区对象,并在其中迭代(使用foreach)通过所有子项

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 C# 中为预先存在的时间添加额外的小时数? - How to add additional hours to pre-existing time in C#? 如何使用C#中预先存在的Windows窗体在选项卡控件中动态创建选项卡页 - How to dynamically create Tab Pages in a Tab Control with a pre-existing Windows Form in C# Visual C#:将功能区按钮添加到“开始”选项卡? (Outlook加载项) - Visual C#: Add ribbon button to start tab? (Outlook add in) 我可以将预先存在的 Javascript 代码添加到 ASP.NET MVC C# 应用程序吗 - Can I add pre-existing Javascript code to an ASP.NET MVC C# application 如何从字符串中拉出变量我需要与另一个预先存在的字符串C#进行比较 - How to pull a variable out of a string I need to compare to another, pre-existing string c# C#如何使用字符串引用具有相同名称的预先存在的变量? - C# How can I used a string to reference a pre-existing variable by the same name? 如何在功能区面板AutoCAD 2009 C#上添加新选项卡? - How add new tab on ribbon panel autocad 2009 C#? 如何在运行时连接到办公室流利的功能区并在c#中添加/操作功能区选项卡? - How do I connect to an office fluent ribbon at runtime and add/manipulate a ribbon tab in c#? 使用预先存在的私钥对文件签名以创建证书(C#) - Using a pre-existing private key to sign file to create a certificate (C#) 我可以在C#中使用的快速预先存在的可嵌入脚本语言 - Fast Pre-existing embeddable scripting language I can use in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM