2017-12-17 20 views
0

カスタムタスクペインを持つPowerPoint VSTO Addinと、トグルボタンで表示/非表示を定義するリボンが作成されました。カスタムタスクペインのステータス。これの基礎は、カスタムタスクペインのMicrosoft Walkthrough情報と、タスクペインとのリボンの同期でした。 最初のPowerPointウィンドウですべてがうまく動作します。タスクペインを2番目と3番目のPowerPointウィンドウに表示することはできますが、リボンのトグルボタンは最後に開いた/作成したPowerPointウィンドウにのみ反応し、アクティブなPowerPointウィンドウでは表示/非表示のタスクウィンドウに反応しません。別のウィンドウにあるC#VSTO-Powerpoint-TaskPanes

私はここに正確に同じ問題を説明し、別のスレッド発見しました: C# VSTO-Powerpoint-TaskPanes in separate windows.

をしかし、私は答えを理解していません。どちらも私はパワーポイントインスペクタラッパーを実装する方法がわかりません。

私はC#で新しく、「Inspector Wrapper」のようなキーワードを取得するのは私にとってはあまりありません。私はすでにネットを検索するのに何時間も費やしていますが、今まで成功していませんでした。

PowerPoint用の完全なコード例を得る機会はありますか?これはどのように動作するのですか?

コードを追加: 私は一般的なウォークスルーからコードを取っ:https://msdn.microsoft.com/en-us/library/bb608590.aspx、新たなプレゼンテーションのためのイベントでそれを変更:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml.Linq; 
using PowerPoint = Microsoft.Office.Interop.PowerPoint; 
using Office = Microsoft.Office.Core; 

namespace PowerPointAddIn1 
{ 
    public partial class ThisAddIn 
    { 
     private TaskPaneControl taskPaneControl1; 
     private Microsoft.Office.Tools.CustomTaskPane taskPaneValue; 

     private void ThisAddIn_Startup(object sender, System.EventArgs e) 
     { 
      this.Application.AfterNewPresentation += new Microsoft.Office.Interop.PowerPoint.EApplication_AfterNewPresentationEventHandler(NewPresentation); 
      //taskPaneControl1 = new TaskPaneControl(); 
      //taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "MyCustomTaskPane"); 
      //taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged); 
     } 

     void NewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation oPres) 
     { 

      PowerPoint.Application app = this.Application; 
      PowerPoint.DocumentWindow docWin = null; 

      foreach (PowerPoint.DocumentWindow win in Globals.ThisAddIn.Application.Windows) 
      { 
       if (win.Presentation.Name == app.ActivePresentation.Name) 
       { 
        docWin = win; 
       } 
      } 

      this.taskPaneControl1 = new TaskPaneControl(); 
      this.taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "MyCustomTaskPane", docWin); 
      this.taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged); 
     } 

     private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e) 
     { 
      Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked = 
      taskPaneValue.Visible; 
     } 

     public Microsoft.Office.Tools.CustomTaskPane TaskPane 
     { 
      get 
      { 
       return taskPaneValue; 
      } 
     } 

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

コード裁判を私たちと共有してください – Marcel

+0

私はコードを一般的なチュートリアルから取りました:https://msdn.microsoft.com/en-us/library/bb608590.aspx –

+0

あなたは2007年をターゲットにしていますか?そうでないかぎり、解決策は 'InspectorWrapper'ではなく、' CustomTaskPane'コレクションと関係しています。 – Chris

答えて

0

:ThisAddIn.csため

コードは以下の通りです私はあまりにもうまく学習曲線を覚えています。ここで私はあなたの問題に対処すると信じているサンプルです。タスクペインをドキュメントにリンクする必要があります。私はここで新しい文書の命名規則に頼っていましたが、DocumentVariableがはるかに優れた選択肢になります(現在のセッションの終わりに破棄されます)。プレゼンテーションに変数を追加し、コントロールにタスクペインのIDを格納し、それらを比較して正しいタスクペインを取得します。

XMLリボンが必要です(おそらくリボンデザイナを使用することができますが、それはあまり良くありません)。私はこれから定型的で無関係なコードをいくつか削除しました。

ThisAddIn.cs:

namespace PowerPointAddIn1 
{ 
    public partial class ThisAddIn 
    { 
     public static int counter = 0; 

     private void ThisAddIn_Startup(object sender, System.EventArgs e) 
     { 
      this.Application.AfterNewPresentation += Application_AfterNewPresentation; 
     } 

     private void Application_AfterNewPresentation(PowerPoint.Presentation Pres) 
     { 
      int count = ++counter; 

      UserControl1 uc = new UserControl1("task pane " + count); 
      CustomTaskPane ctp = CustomTaskPanes.Add(uc, "custom task pane " + count); 
      ctp.Visible = true; 
     } 

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

     protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject() 
     { 
      return new Ribbon1(); 
     } 
    } 
} 

Ribbon1.cs:

namespace PowerPointAddIn1 
{ 
    [ComVisible(true)] 
    public class Ribbon1 : Office.IRibbonExtensibility 
    { 
     private Office.IRibbonUI ribbon; 

     public Ribbon1() 
     { 
     } 

     public void toggleTaskPane(Office.IRibbonControl control, bool enabled) 
     { 
      var CTPs = Globals.ThisAddIn.CustomTaskPanes; 
      var pres = Globals.ThisAddIn.Application.ActivePresentation; 

      foreach (var x in CTPs) 
      { 
       if (pres.Name.EndsWith(x.Title.Replace("custom task pane ", ""))) 
       { 
        x.Visible = enabled; 
       } 
      } 
     } 

     public bool isPressed(Office.IRibbonControl control) 
     { 
      var CTPs = Globals.ThisAddIn.CustomTaskPanes; 
      var pres = Globals.ThisAddIn.Application.ActivePresentation; 
      foreach (var x in CTPs) 
      { 
       if (pres.Name.EndsWith(x.Title.Replace("custom task pane ", ""))) 
       { 
        return x.Visible; 
       } 
      } 
      return false; 
     } 
    } 
} 

Ribbon1.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> 
    <ribbon> 
    <tabs> 
     <tab idMso="TabAddIns"> 
     <group id="MyGroup" 
       label="My Group"> 
      <checkBox id="mycheckbox" label="show task pane" onAction="toggleTaskPane" getPressed="isPressed" /> 
     </group> 
     </tab> 
    </tabs> 
    </ribbon> 
</customUI> 

UsreControl1.cs(ちょうどそれのラベルを持っている):

namespace PowerPointAddIn1 
{ 
    public partial class UserControl1 : UserControl 
    { 
     public UserControl1(string labelValue) 
     { 
      InitializeComponent(); 

      label1.Text = labelValue; 
     } 
    } 
} 
+0

Chrisにあなたのご意見をありがとうございます - 私はこの週末をチェックします。多分あなたはアイデアを持っているかもしれません - 上で見ることができるように、私は新しいオブジェクトペインをウィンドウオブジェクトに追加しました - これは現在アクティブなウィンドウが作成されたときのリンクだと思っていました - これはウィンドウプロパティ(提示1)。 しかし、私は新しいプレゼンテーションを作成し、このイベントで現在のウィンドウを持つ新しいカスタム作業ウィンドウも、最初のctpはプレゼンテーション1ではなく新しいプレゼンテーション(2)をウィンドウに表示しました。なぜこれは更新されますか?これは避けられますか? –

+0

Chrisさん、ドキュメント変数(PowerPointのタグ=プレゼンテーションレベルのタグ)のヒントを助けてくれました.CTPとPresentation.Tagを比較できるようになりました。今度は、同じプレゼンテーションごとにCTPを個別に表示/非表示できますトグルボタン。 次のステップは、ドキュメントが閉じられたときなどにCTPを管理することです。メリークリスマス! –

0

私は今私のために働く私の結果を共有したいだけです(私に貴重な情報をくれたChrisに感謝します)。私は、各プレゼンテーションのために働くcustomtaskpane管理を持っています。まだ実装されていないのは、ユーザーが別のウィンドウ(表示/新規ウィンドウ)でドキュメントを開く場合だけです。これは私が管理する方法を知らない。 私はそれをテストすることができるように運賃は今動作します。 ここに全体のソリューションへのリンクがあります: https://happypc-my.sharepoint.com/personal/roger_heckly_happy-pc_ch/_layouts/15/guestaccess.aspx?docid=0426d40dc5df74d66ba42a3b928111ce8&authkey=Aa6yX6QWUnqXp1jcUfGveL8

私は初心者ですので、フィードバック/入力があれば教えてください。確かに、いくつかのコードは簡単に書くことができます。

関連する問題