代码之家  ›  专栏  ›  技术社区  ›  NakedBrunch

如何捕获PowerPoint VSTO文本更改事件?

  •  2
  • NakedBrunch  · 技术社区  · 16 年前

    我正在开发一个PowerPoint C#VSTO插件。我希望能够在幻灯片标题文本更改时捕获文本更改事件。

    如何附加在标题文本更改时触发的自定义事件处理程序?

    1 回复  |  直到 16 年前
        1
  •  3
  •   Todd Main    14 年前

    两件事:1)这是在VBA中,但应该很容易移植到C#和VSTO;2)“文本更改”的事情有点棘手。我可以告诉你“你在一个标题框中吗”-其余的都是琐碎的。它与找到原始状态和任何更改有关。可能我还没有做到。

    要在PPT VBA中钩住选择更改,您需要一个类和一个模块。在课堂上,写下:

    Public WithEvents PPTEvent As Application
    Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
        With Sel
            If .Type = ppSelectionText Then
                Dim sh As Shape: Set sh = .ShapeRange(1)
                If sh.Type = msoPlaceholder Then
                    originalText = sh.TextFrame.Text
                    Dim placeHolderType As Integer
                    placeHolderType = sh.PlaceholderFormat.Type
                    If placeHolderType = ppPlaceholderTitle Then
                        MsgBox "this is a title placeholder"
                    End If
                End If
            End If
        End With
    End Sub
    

    将类命名为“clsPPTEvents”。然后在任何模块中,输入以下内容:

    Public newPPTEvents As New clsPPTEvents
    Sub StartEvents()
        Set newPPTEvents.PPTEvent = Application
    End Sub
    Sub EndEvents()
        Set newPPTEvents.PPTEvent = Nothing
        Set newPPTEvents = Nothing
    End Sub
    

    F5