在MS PowerPoint中添加OnClick操作以形状对象

时间:2016-01-22 13:23:52

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

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

这样的活动
SlideSelectionChanged

WindowBeforeRightClick

哪个不能正常工作,右键单击事件甚至不能在形状对象上工作。

有没有办法订阅这类事件,我不想使用MACRO,但如果不可避免,我会使用它。

1 个答案:

答案 0 :(得分:0)

此解决方案可行。

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设置一些标志来确保你只需要在所需的Shape对象上做必要的事情

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