在Word加载项中打开Windows窗体

时间:2017-08-02 16:02:51

标签: c#

大家好,所以我创建了一个简单的Windows窗体,即用户控件。在我的添加启动时,我想调用该用户控件。当我运行应用程序时,它所做的只是打开一个Word应用程序,而不加载表格的信息,这应该像侧窗格。

这是我到目前为止所拥有的。

namespace WordAddIn2
{
    public partial class ThisAddIn
    {
        SidePane sP;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            sP = new SidePane();
            sP.Show();
        }

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

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

这是Sidepane表格:

namespace WordAddIn2
{
    public partial class SidePane : UserControl
    {
        public SidePane()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Process.Start("explorer.exe", "-p");
        }
    }
}

如果有人可以帮我识别我的简单错误,那就太棒了。

1 个答案:

答案 0 :(得分:1)

这是我想出的解决方案,感谢@Crowcoder。请记住将您的可见性设置为真......

namespace WordAddIn2
{
    public partial class ThisAddIn
    {
        SidePane sP;
        private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            sP = new SidePane();
            myCustomTaskPane = this.CustomTaskPanes.Add(sP, "Title");
            myCustomTaskPane.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
    }
}