gpt4 book ai didi

C#、Word 2003 加载项和工具栏按钮事件

转载 作者:行者123 更新时间:2023-11-30 18:09:55 26 4
gpt4 key购买 nike

我正在尝试为 Word 2003 编写应用程序级加载项。该插件在新的命令栏上添加了一个按钮 - 单击该按钮可保存事件文档,然后执行一些其他操作。当我启动 Word 2003 然后单击命令栏按钮时,一切正常。 但是,如果我启动 Word 2003,通过单击“标准”工具栏上的工具栏按钮“新建文档”打开一个新的 Word 窗口,然后单击我的命令栏按钮,结果没有执行任何操作。似乎我在新打开的窗口上的工具栏按钮没有分配“onclick”事件处理程序。你知道如何解决这个问题吗?
我的加载项代码基于以下代码:

private Office.CommandBar commandBar;
private Office.CommandBarButton docSaveButton;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// prepare toolbar:
try
{
commandBar = Application.CommandBars["MY_TOOLBAR"];
}
catch (ArgumentException)
{
//...
}

if (commandBar == null)
{
commandBar = Application.CommandBars.Add("MY_TOOLBAR", 1, missing, true);
}
commandBar.Visible = true;

// addbutton:
docSaveButton = (Office.CommandBarButton)commandBar.Controls.Add(1, missing, missing, missing, missing);
docSaveButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon;
docSaveButton.Caption = "My save";
docSaveButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(docSaveButtonClick);
}

private void docSaveButtonClick(Office.CommandBarButton ctrl, ref bool cancel)
{
MessageBox.Show("Hello !", "Hello !", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

问候简克

最佳答案

我怀疑您的“加载项”未加载,但您的工具栏已保留。您是否已将“加载项”放置在 Word 的启动位置之一?

有关模板在 Word 2003 或 Word 2007 中的位置的常见问题,Q3:我的 Word 加载项文件保存在哪里? http://support.microsoft.com/kb/826867 .

加载 Word 加载项,第二个项目符号,http://msdn.microsoft.com/en-us/library/aa165426(office.10).aspx

•Automatically when Word starts, by saving the template file in the Word Startup folder on your computer. The default path to this folder is C:\Windows\Application Data\Microsoft\Word\Startup; if you're using user profiles, the default path is C:\Windows\Profiles\UserName\Application Data\Microsoft\Word\Startup. You can change this path in the Options dialog box

关于C#、Word 2003 加载项和工具栏按钮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2108283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com