C# 在Word加载项中打开Windows窗体

C# 在Word加载项中打开Windows窗体,c#,C#,大家好,我创建了一个简单的windows窗体,它是一个用户控件。在外接程序启动时,我想调用该用户控件。当我运行应用程序时,它所做的就是打开一个Word应用程序,而不加载表单的信息,表单的信息应该像一个侧窗格 这是我到目前为止所拥有的 namespace WordAddIn2 { public partial class ThisAddIn { SidePane sP; private void ThisAddIn_Startup(object se

大家好,我创建了一个简单的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
    }
}

如果有人能帮我识别我的简单错误,那就太好了。

感谢@Crowcoder,我想出了一个解决方案。记住将可见性设置为true

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
    }
}
namespace WordAddIn2
{
公共部分类ThisAddIn
{
侧窗格玻璃;
专用Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
私有void ThisAddIn_启动(对象发送方,System.EventArgs e)
{
sP=新侧窗格();
myCustomTaskPane=this.CustomTaskPanes.Add(sP,“Title”);
myCustomTaskPane.Visible=true;
}
私有void ThisAddIn_关闭(对象发送方,System.EventArgs e)
{
}
#区域VSTO生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InternalStartup()
{
this.Startup+=new System.EventHandler(ThisAddIn\u启动);
this.Shutdown+=new System.EventHandler(ThisAddIn\u Shutdown);
}
#端区
}
}

我不熟悉
侧窗格
,但我使用它创建了一个
自定义任务窗格
,然后您可以设置宽度、可见等:
全局。ThisAddIn.CustomTaskPanes.Add(,“”)侧窗格只是我表单的名称。我把它命名为行动应该做的。。。抱歉弄糊涂了,我应该看到的。因此,只需将其实例添加到
Globals.ThisAddin.CustomTaskPanes
中,当我启动外接程序时,它仍然不会显示,:/好的,感谢您的帮助,我让它工作了,我只需要将可见性设置为true
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
    }
}