我可以使用 Visual Studio 在 Microsoft Project 中创建 CustomTaskPane 吗?

Can I create a CustomTaskPane in Microsoft Project using Visual Studio?

Visual Studio 2015.

我已经按照这个简短的 tutorial 在 Word 中创建了一个 CustomTaskPane。我已经设法让它工作了。我想为 Microsoft Project 做同样的事情,但我遇到了第一个障碍:

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 WordAddIn1
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            UserControl1 uc = new UserControl1();

            Microsoft.Office.Tools.CustomTaskPane ctp = CustomTaskPanes.Add(uc, "Title");
            ctp.Visible = true;
        }

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

        #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
    }
}

以上适用于 Word AddIn,但当我尝试为 Project AddIn 执行此操作时出现以下错误:

Severity Code Description Project File Line Error CS0103 The name 'CustomTaskPanes' does not exist in the current context MSProjectAddIn1 D:\DevProjects\MSProjectAddIn1\MSProjectAddIn1\ThisAddIn.cs 17

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


namespace MSProjectAddIn1
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            UserControl1 uc = new UserControl1();

            Microsoft.Office.Tools.CustomTaskPane ctp = CustomTaskPanes.Add(uc, "Title");
            ctp.Visible = true;
        }

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

        #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
    }
}

有人为 MSProject 创建了 CustomTaskPane 吗?

经过大量谷歌搜索后,我在发布到堆栈交换后不久找到了答案 - 不知道为什么,但是访问 CustomTaskPanes 的方式在 MSProject 中是不同的:

UserControl1 uc = new UserControl1();

Microsoft.Office.Tools.CustomTaskPaneCollection customPaneCollection;
customPaneCollection = Globals.Factory.CreateCustomTaskPaneCollection(null, null, "Panes", "Panes", this);

Microsoft.Office.Tools.CustomTaskPane ctp = customPaneCollection.Add(uc, "Title");
ctp.Visible = true;