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

时间:2015-11-27 12:26:52

标签: c# visual-studio ms-project office-addins

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执行此操作时出现以下错误:

  

严重级代码说明项目文件行   错误CS0103当前上下文中不存在名称“CustomTaskPanes”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?

1 个答案:

答案 0 :(得分:1)

经过大量谷歌搜索后,我在发布到堆栈交换后不久找到了答案 - 不确定原因,但在MSProject中访问CustomTaskPanes的方式不同:

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;