2011/10/01

access2010 VSTOアプリケーションアドイン -5-

CustomTaskPaneを使えるようにしておくメモ

CustomTaskPaneの表示非表示に連動するリボンコントロールにはdynamicMenuを使用。invalidateContentOnDropで更新に手間がかからないから。

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" 
          onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab id="test" label="taskpanesDemo" insertBeforeMso="TabHomeAccess">
        <group id ="g01">
          <dynamicMenu id="dm1" 
                       label="TaskPanes" 
                       getContent="dmGetContent" 
                       invalidateContentOnDrop="true"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
Public Class ThisAddIn
    Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
        Return New Ribbon1()
    End Function

    Public ReadOnly Property TaskPanes As Microsoft.Office.Tools.CustomTaskPaneCollection
        Get
            Return Me.CustomTaskPanes
        End Get
    End Property

    Private Sub ThisAddIn_Startup() Handles Me.Startup
        Me.CustomTaskPanes.Add(New UserControl1, "TaskPane1")
        Me.CustomTaskPanes.Add(New UserControl2, "TaskPane2")
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub
End Class
Public Function dmGetContent(control As Office.IRibbonControl) As String
    Dim taskpanes As Microsoft.Office.Tools.CustomTaskPaneCollection =
        Globals.ThisAddIn.TaskPanes
    Dim sb As New StringBuilder
    sb.Append("<menu xmlns=""http://schemas.microsoft.com/office/2009/07/customui"" itemSize=""large"">")
    For i As Integer = 0 To taskpanes.Count - 1
        sb.Append("<toggleButton ")
        sb.AppendFormat("id=""{0}"" label=""{1}"" tag=""{2}""",
                        "taskpane" + i.ToString,
                        taskpanes(i).Title,
                        i.ToString)
        sb.Append(" getPressed=""dmtglGetPressed""")
        sb.Append(" onAction=""dmtglOnAction"" />")
    Next
    sb.Append("</menu>")
    Return sb.ToString
End Function

Public Function dmtglGetPressed(control As Office.IRibbonControl) As Boolean
    Return Globals.ThisAddIn.CustomTaskPanes(CInt(control.Tag)).Visible
End Function

Public Sub dmtglOnAction(control As Office.IRibbonControl, Pressed As Boolean)
    Globals.ThisAddIn.CustomTaskPanes(CInt(control.Tag)).Visible = Pressed
End Sub
なんでTaskPanesプロパティつくったかな

0 件のコメント: