[英]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进行任何更改,所以我猜:
TabHome
is wrong (at least for Outlook 2010), TabHome
是错误的(至少对于Outlook 2010), idMso
is wrong (at least for Outlook 2010) or idMso
是错误的(至少对于Outlook 2010)或 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.