【问题标题】:Add OnClick Action to Shape Objects in MS PowerPoint在 MS PowerPoint 中为形状对象添加 OnClick 动作
【发布时间】:2016-01-22 13:23:51
【问题描述】:

我需要在使用 C# 语言构建的 Office 2010 及更高版本的 Microsoft Power Point Addin 中向 Shape 对象添加 OnClick 操作。有像

这样的事件
SlideSelectionChanged

WindowBeforeRightClick

按需要不起作用,右键单击事件甚至对形状对象不起作用。

有没有办法订阅这种类型的事件,我不喜欢使用 MACRO 但是如果这是不可避免的,我会使用它。

【问题讨论】:

  • 最近这里有类似的问题。 Maybe it can help you。它是关于 excel 的,但许多 API 与 MS Office 产品相同。

标签: c# wpf-controls powerpoint office-addins powerpoint-2010


【解决方案1】:

此解决方案可行。

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

void OnWindowSelectionChanged(PowerPoint.Selection Sel)
    {
        if (Sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
        {
             PowerPoint.ShapeRange shapeRange = Sel.ShapeRange;
             //Do some work
        }
    }

private void ThisAddIn_ShutDown(object sender, System.EventArgs e)
    {
        this.Application.WindowSelectionChange -= OnWindowSelectionChanged;
    }

最好有一些标志,以确保您只在所需的形状对象上做必要的事情,方法是使用 AltText 设置一些标志,例如

if (Sel.ShapeRange.AlternativeText.Contains("SomeFlag"))
   {
      //Do some thing
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 2019-10-13
    • 2016-02-04
    相关资源
    最近更新 更多