powerpoint c# add-in shape grouping issue

妖精的绣舞 提交于 2019-12-01 20:48:46

Your code worked fine for me. Try this:

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

void Application_PresentationNewSlide(PowerPoint.Slide Sld) {
    PowerPoint.Shape textBox = Sld.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 500, 50);
    textBox.Name = "shape1";
    textBox.TextFrame.TextRange.InsertAfter("This text was added by using code.");

    textBox = Sld.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, 100, 500, 50);
    textBox.TextFrame.TextRange.InsertAfter("This text was also added by using code.");
    textBox.Name = "shape2";

    PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
    PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;
    string[] myRangeArray = new string[2];
    myRangeArray[0] = "shape1";
    myRangeArray[1] = "shape2";
    curSlide.Shapes.Range(myRangeArray).Group();
}

If the layout of the slide you're starting with includes a content placeholder or other placeholder that can contain an ole object, PPT is probably popping the newly created OLE object INTO that placeholder. Placeholders cannot be grouped with other shapes. If that turns out to be the problem, either start with a slide whose layout doesn't include a placeholder that can contain OLE objects, or delete the placeholder before creating your OLE object, or create the OLE object, duplicate it (giving you an OLE object that's not contained in a placeholder), then delete the original.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!