PowerPoint中的C#外接形状分组问题 [英] powerpoint c# add-in shape grouping issue

查看:190
本文介绍了PowerPoint中的C#外接形状分组问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个PowerPoint 2010中添加使用Visual Studio 2010和我有同一个幻灯片编组两个对象显著的问题。我想创建两个对象,将它们放置在相同功能的幻灯片,他们全部组。添加的对象并将它们放置在滑动不是一个问题。当谈到分组的一部分虽然....

I developing a PowerPoint 2010 add-in using Visual Studio 2010 and am having significant issues with grouping two objects on a slide. I am trying to create the two objects, place them on the slide and group them all in the same function. Adding the objects and placing them on the slide is not an issue. When it comes to the grouping part though....

我曾尝试:

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

PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;
curSlide.Shapes.Range(Array("nameOfShape0", "nameOfShape1")).Group();



这两者的惨败。我得到这个非常沮丧,我真的希望某种灵魂有我一个解决方案。谢谢

Both of which fail miserably. I am getting quite frustrated with this and am really hoping some kind soul has a solution for me. Thanks.

更新:
下面是我使用的完整代码:

Update: Here is the full code I am using:

PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;

PowerPoint.Shape browser = curSlide.Shapes.AddOLEObject(110, 70, 500, 400, "Shell.Explorer.2");
var slideName = "webBrowser_0";
browser.Name = slideName;

PowerPoint.Shape rectangle = curSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 110, 70, 500, 400);
rectangle.Name = "shape2";
string[] myRangeArray = new string[2];
myRangeArray[0] = "webBrowser_0";
myRangeArray[1] = "shape2";
curSlide.Shapes.Range(myRangeArray).Group();



我收到的错误是ShapeRange对象必须包含至少两个项目

The Error I am receiving is "The ShapeRange object must contain at least two items"

推荐答案

您的代码为我工作的罚款。试试这个:

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();
}

这篇关于PowerPoint中的C#外接形状分组问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆