2017-08-02 9 views
0

こんにちは皆、私はユーザーコントロールである単純なウィンドウフォームを作成しました。私のアドインの起動時に、私はそのユーザーコントロールを呼びたいと思う。アプリケーションを実行すると、サイドウィンドウのようなフォームの情報を読み込まずに、Wordアプリケーションが開かれます。WordアドインでWindowsフォームを開く

これまで私がこれまで持っていたことは次のとおりです。ここで

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

は、サイドペインの形式である:

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"); 
     } 
    } 
} 

誰かが私が私の単純なエラーを識別するのに役立つことができれば、それは素晴らしいだろう。

+0

にあなたの可視性を設定することを忘れないでください。 ThisAddIn.CustomTaskPanes.Add(、 "<任意の名前/タイトル>"); ' – Crowcoder

+0

SidePaneは私のフォームの名前です。私はその行為が何をすべきかという名前をつけた...混乱のために残念。 –

+0

そう、それを見たはずだった。だから、そのインスタンスを 'Globals.ThisAddin.CustomTaskPanes'に追加してください。 – Crowcoder

答えて

1

@Crowcoderのおかげで私が思いついた解決策がここにあります。 `グローバル:私は` SidePane`に慣れていないんだけど、私はあなたがして目に見える幅、などを設定することができ `CustomTaskPane`を作成するこれを使用して、真...

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