【问题标题】:Can I create a CustomTaskPane in Microsoft Project using Visual Studio?我可以使用 Visual Studio 在 Microsoft Project 中创建 CustomTaskPane 吗?
【发布时间】:2015-11-27 12:26:52
【问题描述】:

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 插件,但当我尝试为项目插件执行此操作时出现以下错误:

严重性代码描述项目文件行 错误 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 吗?

【问题讨论】:

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


    【解决方案1】:

    经过大量谷歌搜索,我在发布到堆栈交换后不久就找到了答案 - 不知道为什么,但访问 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2020-02-28
      • 2011-10-04
      相关资源
      最近更新 更多