是否可以在Word中向CommandBar [“Text”]添加编辑框或组合框?

时间:2011-04-19 09:55:30

标签: c# ms-word ms-office add-in office-addins

我正在尝试在加载Word加载项时向其中一个上下文菜单添加编辑框或组合框。但我没有成功,我没有得到任何错误,编辑/组合框只是没有显示。

this.Application.CommandBars["Text"].Reset();

// add a menu to the context menu
CommandBarPopup subMenu = (CommandBarPopup)this.Application.CommandBars["Text"].Controls
  .Add(Office.MsoControlType.msoControlPopup, missing, missing, 1, true);

subMenu.Caption = "My menu";

// add combo box to the newly created menu
CommandBarComboBox ctrl = (CommandBarComboBox)subMenu.Controls
  .Add(MsoControlType.msoControlComboBox, missing, missing, 1, true);

ctrl.Caption = "Bleh";
ctrl.Text = "Blah";
ctrl.AddItem("Hai", 1);
ctrl.AddItem("Hoi", 2);
ctrl.DropDownLines = 3;
ctrl.DropDownWidth = 75;
ctrl.ListIndex = 0;
ctrl.Visible = true;

上面的代码在Word中的右键单击上下文菜单中添加了一个菜单,称为“我的菜单”,然后我尝试向该菜单添加一个组合框,它不会显示。代码在我的加载项启动函数中。

有没有人有这方面的经验?它甚至可能吗?或者我只是做了一些错误的事情?



更新

我想有一些关于这方面的文档。但我似乎无法找到它。这是我发现的文件:
http://msdn.microsoft.com/en-us/library/aa190799(v=office.10).aspx
从阅读中,我得到的印象应该是可以添加CommandBarPopup,CommandBarComboBox和CommandBarButton。

1 个答案:

答案 0 :(得分:0)

据我所知,您不能在菜单中放置任何“编辑”控件,只能将它们放在工具栏中。如果我没记错的话,菜单可以包含间隔符或MenuCommandButtons或子菜单。