C# Office Development : Microsoft. Office.Tools.Word.Controls.Button 给出错误

标签 c# ms-word add-in ribbon

我正在阅读 tutorial on how to use control blocks to manipulate document in word .
问题在于声明:

private Microsoft.Office.Tools.Word.Controls.Button button = null;

出现错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;

namespace SecondWordAddIns {
    public partial class ThisAddIn {
        private Microsoft.Office.Tools.Word.Controls.Button button = null; // error here

        private RichTextContentControl richTextControl = null;

        private void ThisAddIn_Startup(object sender, System.EventArgs e) { }
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { }
        internal void toggleButton() { }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

错误信息:

Error 1 The type or namespace name 'Controls' does not exist in the namespace 'Microsoft.Office.Tools.Word' (are you missing an assembly reference?) C:\Users\root\Documents\Visual Studio 2010\Projects\WordAddIn2\WordAddIn2\ThisAddIn.cs 14 45 WordAddIn2

最佳答案

首先您需要 Microsoft.Office.Tools.Word.v4.0.Utilities.dll。您有吗?

如果是的话, 在您的解决方案资源管理器中: 引用-> 添加引用 -> 将 Microsoft.Office.Tools.Word.v4.0.Utilities 引用添加到您的项目中。

如果您在此步骤中遇到一些错误,请阅读 Google 中的“添加对 Visual Studio 项目的引用”。

关于C# Office Development : Microsoft. Office.Tools.Word.Controls.Button 给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26055798/

相关文章:

c# - 推荐一个扎实的.Net FTP库

c# - 在 Blazor 中根据订阅级别处理用户功能的方法有哪些?

vba - Excel VBA : setting font style and size while adding text to MS-Word

vba - 获取整个Word文档文本到一个数组中,用换行符分割

JavaScript 杂货 list

C#/C++ - 如何获取路径太长或权限被拒绝的目录的大小?

c++ - 我的 Word 加载项的对话框不使用视觉样式

office365 - 具有 Office 加载项 AppDomains 的子域

c# - 我的 visual studio 插件如何在构建之前以与 "Remove and Sort Usings"相同的方式检测编译器错误?

c# - 声明不属于我的类符合 C# 接口(interface)