private static PowerPoint.Shape GetShapeFromSelection(PowerPoint.Selection selection)
        {
            ShapeRange shapeRange = GetShapeRangeFromSelection(selection);
            Shape      shape      = GetShapeFromShapeRange(shapeRange);

            return(shape);
        }
示例#2
0
        private void galleryAlign_ButtonClick(object sender, RibbonControlEventArgs e)
        {
            try
            {
                PowerPoint.Selection selection = Globals.ThisAddIn.Application.ActiveWindow.Selection;
                TopOrLeft            topLeft;

                if (e.Control.Id == buttonAlignLeftToRight.Id)
                {
                    topLeft = TopOrLeft.Left;
                }
                else if (e.Control.Id == buttonAlignTopToBottom.Id)
                {
                    topLeft = TopOrLeft.Top;
                }
                else
                {
                    return;
                }

                ToolsSizeAndPosition.AlignTopToBottom(selection, topLeft);
            }
            catch (Exception ex)
            {
                Exceptions.Handle(ex);
            }
        }
        /// <summary>
        /// Colors specified shape with color.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="rgb"></param>
        private void ColorShapeFontWithColor(PowerPoint.Shape s, int rgb)
        {
            if (s.HasTextFrame == MsoTriState.msoTrue)
            {
                PowerPoint.Selection selection = this.GetCurrentSelection();
                if (selection == null)
                {
                    return;
                }

                if (selection.ShapeRange.HasTextFrame == MsoTriState.msoTrue)
                {
                    if (selection.Type == PowerPoint.PpSelectionType.ppSelectionText)
                    {
                        PowerPoint.TextRange selectedText = selection.TextRange.TrimText();
                        if (selectedText.Text != "" && selectedText != null)
                        {
                            selectedText.Font.Color.RGB = rgb;
                        }
                        else
                        {
                            s.TextFrame.TextRange.TrimText().Font.Color.RGB = rgb;
                        }
                    }
                    else if (selection.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
                    {
                        s.TextFrame.TextRange.TrimText().Font.Color.RGB = rgb;
                    }
                }
            }
        }
示例#4
0
        public void MakeURL(Office.IRibbonControl control)
        {
            PowerPoint.Application  appl            = Globals.ThisAddIn.Application;
            PowerPoint.Presentation thePresentation = appl.ActivePresentation;
            PowerPoint.Slide        theSlide        = appl.ActiveWindow.View.Slide;
            PowerPoint.Selection    selection       = appl.ActiveWindow.Selection;
            String urlstring = UrlHandler.Program.PREFIX + thePresentation.FullName;

            urlstring += "#" + theSlide.SlideIndex;
            if (control.Id.StartsWith("MakeURLShape") ||
                control.Id.StartsWith("MakeURLTextEdit") ||
                control.Id.StartsWith("MakeURLObjectsGroup"))
            {
                urlstring += "!";
                String[] names = new String[selection.ShapeRange.Count];
                for (int i = 0; i < selection.ShapeRange.Count; i++)
                {
                    urlstring += selection.ShapeRange[1 + i].Name + ",";
                }
                urlstring = urlstring.Substring(0, urlstring.Length - 1); // trim trailing [!,]
            }
            // paste text to clipboard
            DataObject data = new DataObject();

            data.SetData(DataFormats.Text, urlstring);
            // paste html to clipboard
            string cf_html = HTMLClipboardFormat(urlstring);

            byte[] cf_html_bytes = Encoding.UTF8.GetBytes(cf_html);
            data.SetData(DataFormats.Html, new MemoryStream(cf_html_bytes));
            Clipboard.SetDataObject(data, true);
        }
示例#5
0
 private void button1_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type != PowerPoint.PpSelectionType.ppSelectionSlides)
     {
         MessageBox.Show("请先选中要粘贴备注的幻灯片页面");
     }
     else
     {
         string txt = richTextBox1.Text.Trim();
         if (checkBox1.Checked)
         {
             foreach (PowerPoint.Slide slide in sel.SlideRange)
             {
                 if (checkBox2.Checked)
                 {
                     slide.NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text = txt + Environment.NewLine + slide.NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text;
                 }
                 else
                 {
                     slide.NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text = slide.NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text + Environment.NewLine + txt;
                 }
             }
         }
         else
         {
             foreach (PowerPoint.Slide slide in sel.SlideRange)
             {
                 slide.NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text = txt;
             }
         }
     }
 }
        /// <summary>
        /// Retrieves selected shapes or text.
        /// </summary>
        private void SelectShapes()
        {
            try
            {
                PowerPoint.Selection selection = this.GetCurrentSelection();
                if (selection == null)
                {
                    return;
                }

                if (selection.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
                {
                    _selectedShapes = ShapeUtil.GetShapeRange(selection);
                }
                else if (selection.Type == PowerPoint.PpSelectionType.ppSelectionText)
                {
                    _selectedText = selection.TextRange;
                }
                else
                {
                    _selectedShapes = null;
                    _selectedText   = null;
                }
            }
            catch (Exception)
            {
                _selectedShapes = null;
                _selectedText   = null;
            }
        }
示例#7
0
 private void button2_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
     {
         MessageBox.Show("请先选中要复制的形状");
     }
     else
     {
         PowerPoint.Slide      slide = app.ActiveWindow.View.Slide;
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         float rn     = float.Parse(textBox2.Text);
         int   scount = int.Parse(textBox3.Text);
         oshape = range[1];
         for (int i = 1; i <= scount; i++)
         {
             PowerPoint.Shape nshape = oshape.Duplicate()[1];
             nshape.Rotation = oshape.Rotation + i * rn;
             nshape.Left     = oshape.Left;
             nshape.Top      = oshape.Top;
             nshape.Select();
         }
     }
 }
示例#8
0
        private void button1_Click(object sender, EventArgs e)
        {
            PowerPoint.Selection sel = app.ActiveWindow.Selection;
            if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
            {
                MessageBox.Show("请先选中一个形状");
            }
            else
            {
                PowerPoint.Slide      slide = app.ActiveWindow.View.Slide;
                PowerPoint.ShapeRange range = sel.ShapeRange;
                if (sel.HasChildShapeRange)
                {
                    range = sel.ChildShapeRange;
                }
                else
                {
                    range = sel.ShapeRange;
                }
                int count = range.Count;

                for (int i = 1; i <= count; i++)
                {
                    PowerPoint.Shape shape = range[i];
                    shape.Rotation = float.Parse(textBox1.Text);
                }
            }
        }
示例#9
0
 private void button5_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
     {
         forms.MessageBox.Show("请选中至少一个形状");
     }
     else
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         else
         {
             range = sel.ShapeRange;
         }
         int count = range.Count;
         for (int i = 1; i <= count; i++)
         {
             range[i].Rotation = 0;
         }
     }
 }
示例#10
0
 public override void InsertLink(String path, String titulo)
 {
     PowerPoint.Selection selection = presentation.Application.ActiveWindow.Selection;
     PowerPoint.Hyperlink hyperlink = selection.TextRange.ActionSettings[Microsoft.Office.Interop.PowerPoint.PpMouseActivation.ppMouseClick].Hyperlink;
     hyperlink.Address       = path;
     hyperlink.TextToDisplay = titulo;
 }
示例#11
0
 public static void ApplyPosition(PowerPoint.Selection selection, PowerPointPosition point)
 {
     selection.ShapeRange[1].Left   = point.Left;
     selection.ShapeRange[1].Top    = point.Top;
     selection.ShapeRange[1].Width  = point.Width;
     selection.ShapeRange[1].Height = point.Height;
 }
        private PowerPoint.Shape ConvertToSpotlightPicture(List <PowerPoint.Shape> spotlightShapes)
        {
            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(this.Index);
            List <String> shapeNames = new List <String>();

            shapeNames.Add("SpotlightShape1");
            foreach (PowerPoint.Shape sh in spotlightShapes)
            {
                shapeNames.Add(sh.Name);
            }
            String[] shapeNamesArray       = shapeNames.ToArray();
            PowerPoint.ShapeRange newRange = this.Shapes.Range(shapeNamesArray);
            newRange.Select();

            PowerPoint.Selection currentSelection = Globals.ThisAddIn.Application.ActiveWindow.Selection;

            // Save the original dimensions because ppPastePNG is resized in PowerPoint 2016
            float originalWidth  = currentSelection.ShapeRange[1].Width;
            float originalHeight = currentSelection.ShapeRange[1].Height;

            currentSelection.Cut();

            PowerPoint.Shape spotlightPicture = this.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
            spotlightPicture.Width  = originalWidth;
            spotlightPicture.Height = originalHeight;

            return(spotlightPicture);
        }
示例#13
0
        private void button2_Click(object sender, EventArgs e)
        {
            PowerPoint.Slide     slide = app.ActiveWindow.View.Slide;
            PowerPoint.Selection sel   = app.ActiveWindow.Selection;
            string cha = textBox1.Text.Trim();
            int    cn  = int.Parse(textBox2.Text.Trim());

            if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
            {
                PowerPoint.Shape txt = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 100, 100);
                txt.TextFrame2.TextRange.Text = new string(char.Parse(cha), cn);
                txt.Select();
            }
            else
            {
                string[] name = new string[sel.ShapeRange.Count];
                for (int i = 1; i <= sel.ShapeRange.Count; i++)
                {
                    PowerPoint.Shape txt = sel.ShapeRange[i];
                    txt.TextFrame2.TextRange.Text = txt.TextFrame2.TextRange.Text + new string(char.Parse(cha), cn);
                    name[i - 1] = txt.Name;
                }
                slide.Shapes.Range(name).Select();
            }
        }
示例#14
0
 private void button6_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         for (int i = 1; i <= sel.ShapeRange.Count; i++)
         {
             PowerPoint.Shape txt = sel.ShapeRange[i];
             if (txt.TextFrame.TextRange.Font.Subscript == Office.MsoTriState.msoFalse)
             {
                 txt.TextFrame.TextRange.Font.Subscript = Office.MsoTriState.msoTrue;
             }
             else
             {
                 txt.TextFrame.TextRange.Font.Subscript = Office.MsoTriState.msoFalse;
             }
         }
     }
     else if (sel.Type == PowerPoint.PpSelectionType.ppSelectionText)
     {
         if (sel.TextRange.Font.Subscript == Office.MsoTriState.msoFalse)
         {
             sel.TextRange.Font.Subscript = Office.MsoTriState.msoTrue;
         }
         else
         {
             sel.TextRange.Font.Subscript = Office.MsoTriState.msoFalse;
         }
     }
     else
     {
         MessageBox.Show("请选中文本框");
     }
 }
示例#15
0
 private void textBox2_TextChanged(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes && ((!sel.HasChildShapeRange && (sel.ShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture)) || (sel.HasChildShapeRange && (sel.ChildShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ChildShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture))))
     {
         string n = textBox2.Text.Trim();
         float  b;
         if (n == "" || !float.TryParse(n, out b) || n == "0")
         {
             MessageBox.Show("请输入大于0的数值");
         }
         else
         {
             PowerPoint.ShapeRange range = sel.ShapeRange;
             if (sel.HasChildShapeRange)
             {
                 range = sel.ChildShapeRange;
             }
             else
             {
                 range = sel.ShapeRange;
             }
             int count = range.Count;
             for (int i = 1; i <= count; i++)
             {
                 PowerPoint.Shape pic = range[i];
                 pic.PictureFormat.Crop.PictureHeight = CMtoP(float.Parse(n));
             }
         }
     }
     else
     {
         MessageBox.Show("请先选择一张图片");
     }
 }
示例#16
0
 private void button2_Click(object sender, EventArgs e)
 {
     timer1.Stop();
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         else
         {
             range = sel.ShapeRange;
         }
         int count = range.Count;
         int nr    = panel1.BackColor.R;
         int ng    = panel1.BackColor.G;
         int nb    = panel1.BackColor.B;
         for (int i = 1; i <= count; i++)
         {
             PowerPoint.Shape shape = range[i];
             shape.Fill.Visible       = Microsoft.Office.Core.MsoTriState.msoTrue;
             shape.Fill.ForeColor.RGB = nr + ng * 256 + nb * 256 * 256;
         }
     }
     timer1.Start();
 }
示例#17
0
        private void Highlight(PowerPoint.Selection selection)
        {
            switch (selection.Type)
            {
            default:
            case PowerPoint.PpSelectionType.ppSelectionNone:
                break;

            case PowerPoint.PpSelectionType.ppSelectionSlides:
                Highlight(selection.SlideRange);
                break;

            case PowerPoint.PpSelectionType.ppSelectionShapes:
                Highlight(selection.ShapeRange.Cast <PowerPoint.Shape>());
                break;

            case PowerPoint.PpSelectionType.ppSelectionText:
                if (selection.TextRange.Length > 0)
                {
                    Highlight(selection.TextRange);
                }
                else
                {
                    Highlight(selection.ShapeRange.Cast <PowerPoint.Shape>());
                }
                break;
            }
        }
示例#18
0
        void Application_WindowSelectionChange(Microsoft.Office.Interop.PowerPoint.Selection Sel)
        {
            Microsoft.Office.Interop.PowerPoint.Shape shape = null;
            bool run = false;

            if (Sel.Type == Microsoft.Office.Interop.PowerPoint.PpSelectionType.ppSelectionNone)
            {
                run = true;
            }
            else //if (Sel.Type == Microsoft.Office.Interop.PowerPoint.PpSelectionType.ppSelectionShapes)
            {
                if (Sel.ShapeRange.Count > 0)
                {
                    shape = Sel.ShapeRange[1];

                    // Check if inline equation shape was selected
                    selectTextShape(shape);
                    if (shape != m_oldShape)
                    {
                        //removeInlineEquationShapes(shape);
                        run = true;
                    }
                }
            }
            if (run)
            {
                if (m_oldShape != null)
                {
                    InlineLatex.createInlineEquations(m_oldShape);
                }
                m_oldShape = shape;
            }
        }
示例#19
0
 private void button2_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         if (range.Count == 1)
         {
             range[1].Left = app.ActivePresentation.PageSetup.SlideWidth - range[1].Width;
         }
         else
         {
             for (int i = 2; i <= range.Count; i++)
             {
                 range[i].Left = range[1].Left + range[1].Width - range[i].Width;
             }
         }
     }
     else
     {
         PowerPoint.SlideRange srange = sel.SlideRange;
         float swidth = app.ActivePresentation.PageSetup.SlideWidth;
         foreach (PowerPoint.Slide item in srange)
         {
             for (int i = 1; i <= item.Shapes.Count; i++)
             {
                 item.Shapes[i].Left = swidth - item.Shapes[i].Width;
             }
         }
     }
 }
示例#20
0
        public static void Init(PowerPoint.Application application)
        {
            if (instance == null)
            {
                instance = new PPCopy();
                instance.Visible = false;
                try
                {
                    nextHandle = Native.SetClipboardViewer(instance.Handle);
                    isSuccessful = Native.AddClipboardFormatListener(instance.Handle);
                    //if fails to set up clipboardFormatListener, re-try 5 times
                    for (int i = 0; i < 5; i++)
                    {
                        if (isSuccessful) break;
                        isSuccessful = Native.AddClipboardFormatListener(instance.Handle);
                    }

                    handle = instance.Handle;
                    application.WindowSelectionChange += (selection) =>
                    {
                        selectedRange = selection;
                        if (!isSuccessful)
                        {
                            isSuccessful = Native.AddClipboardFormatListener(instance.Handle);
                        }
                    };
                }
                catch
                {
                    //TODO: support win XP?
                }
            }
        }
示例#21
0
 private void button2_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type != PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         MessageBox.Show("请先选中一个矢量形状");
     }
     else
     {
         PowerPoint.Shape shape = sel.ShapeRange[1];
         if (sel.HasChildShapeRange)
         {
             shape = sel.ChildShapeRange[1];
         }
         if (shape.Type == Office.MsoShapeType.msoAutoShape || shape.Type == Office.MsoShapeType.msoFreeform)
         {
             if (shape.Type == Office.MsoShapeType.msoAutoShape)
             {
                 shape.Nodes.Insert(1, Office.MsoSegmentType.msoSegmentLine, Office.MsoEditingType.msoEditingCorner, 0f, 0f, 0f, 0f, 0f, 0f);
                 shape.Nodes.Delete(2);
             }
             int count = shape.Nodes.Count;
             comboBox1.Items.Clear();
             for (int i = 1; i <= count; i++)
             {
                 comboBox1.Items.Add(i);
             }
         }
         else
         {
             MessageBox.Show("所选图形不可编辑顶点");
         }
     }
 }
示例#22
0
 private void button3_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         if (range.Count == 1)
         {
             range[1].Top = 0;
         }
         else
         {
             for (int i = 2; i <= range.Count; i++)
             {
                 range[i].Top = range[1].Top;
             }
         }
     }
     else
     {
         PowerPoint.SlideRange srange = sel.SlideRange;
         foreach (PowerPoint.Slide item in srange)
         {
             for (int i = 1; i <= item.Shapes.Count; i++)
             {
                 item.Shapes[i].Top = 0;
             }
         }
     }
 }
示例#23
0
 private void button3_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type != PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         MessageBox.Show("请同时选中矢量形状和连接符");
     }
     else
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         int a = 0;
         int b = 0;
         foreach (PowerPoint.Shape item in range)
         {
             if (a == 0)
             {
                 if (item.Type == Office.MsoShapeType.msoAutoShape || item.Type == Office.MsoShapeType.msoFreeform)
                 {
                     a += 1;
                     b  = item.ConnectionSiteCount;
                 }
             }
         }
         comboBox1.Items.Clear();
         comboBox2.Items.Clear();
         for (int i = 1; i <= b; i++)
         {
             comboBox1.Items.Add(i);
             comboBox2.Items.Add(i);
         }
     }
 }
示例#24
0
 private static void VerifyIsSelectionValid(PowerPoint.Selection selection)
 {
     if (selection.Type != PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         ThrowErrorCode(ErrorCodeForSelectionCountZero);
     }
 }
示例#25
0
 private void button1_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes && ((!sel.HasChildShapeRange && (sel.ShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture)) || (sel.HasChildShapeRange && (sel.ChildShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ChildShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture))))
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         else
         {
             range = sel.ShapeRange;
         }
         int   count = range.Count;
         float n     = float.Parse(textBox4.Text.Trim());
         n = CMtoP(n);
         for (int i = 1; i <= count; i++)
         {
             PowerPoint.Shape pic = range[i];
             pic.PictureFormat.Crop.PictureOffsetY -= n;
         }
     }
     else
     {
         MessageBox.Show("请先选择一张图片");
     }
 }
示例#26
0
        public static PowerPoint.Shape Crop(PowerPoint.Selection selection, double magnifyRatio = 1.0, bool isInPlace = false,
                                            bool handleError = true)
        {
            try
            {
                VerifyIsSelectionValid(selection);
            }
            catch (Exception e)
            {
                if (handleError)
                {
                    ProcessErrorMessage(e);
                    return(null);
                }

                throw;
            }

            var croppedShape = Crop(selection.ShapeRange, isInPlace: isInPlace, handleError: handleError);

            if (croppedShape != null)
            {
                croppedShape.Select();
            }

            return(croppedShape);
        }
示例#27
0
 private void button8_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes && ((!sel.HasChildShapeRange && (sel.ShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture)) || (sel.HasChildShapeRange && (sel.ChildShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ChildShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture))))
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         else
         {
             range = sel.ShapeRange;
         }
         int count = range.Count;
         for (int i = 1; i <= count; i++)
         {
             PowerPoint.Shape pic = range[i];
             pic.PictureFormat.Crop.PictureHeight = pic.PictureFormat.Crop.ShapeHeight;
             pic.PictureFormat.Crop.PictureWidth  = pic.PictureFormat.Crop.ShapeWidth;
         }
     }
     else
     {
         MessageBox.Show("请先选择一张图片");
     }
 }
示例#28
0
        private static PowerPoint.Shape GetStepBackWithoutBackgroundShapeToZoom(PowerPointSlide addedSlide, PowerPointSlide previousSlide)
        {
            Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);

            List <PowerPoint.Shape> copiedShapes = new List <PowerPoint.Shape>();

            foreach (PowerPoint.Shape sh in previousSlide.Shapes)
            {
                if (!previousSlide.HasExitAnimation(sh) && !sh.IsHidden())
                {
                    PowerPoint.Shape shapeCopy = addedSlide.Shapes.SafeCopyPlaceholder(sh);
                    LegacyShapeUtil.CopyShapeAttributes(sh, ref shapeCopy);
                    copiedShapes.Add(shapeCopy);
                }
            }

            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);
            SelectAllShape(copiedShapes);
            PowerPoint.Selection sel        = Globals.ThisAddIn.Application.ActiveWindow.Selection;
            PowerPoint.Shape     shapeGroup = sel.ShapeRange.SafeGroup();

            PowerPoint.Shape previousSlidePicture = addedSlide.Shapes.SafeCopyPNG(shapeGroup);
            LegacyShapeUtil.CopyCenterShapePosition(shapeGroup, ref previousSlidePicture);
            previousSlidePicture.Name = "PPTZoomOutShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
            shapeGroup.SafeDelete();

            return(previousSlidePicture);
        }
示例#29
0
        //Return picture copy of next slide where shapes with exit animations have been deleted
        private static PowerPoint.Shape GetNextSlidePictureWithoutBackground(PowerPointSlide currentSlide, PowerPointSlide nextSlide, out PowerPoint.Shape pictureOnNextSlide)
        {
            Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(nextSlide.Index);

            List <PowerPoint.Shape> copiedShapes = new List <PowerPoint.Shape>();

            foreach (PowerPoint.Shape sh in nextSlide.Shapes)
            {
                if (!nextSlide.HasEntryAnimation(sh) && !sh.IsHidden())
                {
                    PowerPoint.Shape shapeCopy = currentSlide.Shapes.SafeCopyPlaceholder(sh);
                    LegacyShapeUtil.CopyShapeAttributes(sh, ref shapeCopy);
                    copiedShapes.Add(shapeCopy);
                }
            }

            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index);
            SelectAllShape(copiedShapes);
            PowerPoint.Selection sel        = Globals.ThisAddIn.Application.ActiveWindow.Selection;
            PowerPoint.Shape     shapeGroup = sel.ShapeRange.SafeGroup();

            pictureOnNextSlide = nextSlide.Shapes.SafeCopyPNG(shapeGroup);
            LegacyShapeUtil.CopyCenterShapePosition(shapeGroup, ref pictureOnNextSlide);
            shapeGroup.SafeDelete();

            PowerPoint.Shape slidePicture = currentSlide.Shapes.SafeCopyPNG(pictureOnNextSlide);
            return(slidePicture);
        }
示例#30
0
        public static void SplitObject(PowerPoint.Selection selection)
        {
            PowerPoint.Shape shape = selection.ShapeRange[1];
            // Get number of paragraphs and original height
            int n = shape.TextFrame2.TextRange.Paragraphs.Count;

            // Set height to 1 / [paragraph count] of original
            shape.Height = shape.Height / n;
            // For each additional paragraph: duplicate, set left and top, remove unnecessary paragraphs
            for (int i = 2; i <= n; i++)
            {
                // Duplicate original shape to create new shape
                PowerPoint.Shape s = shape.Duplicate()[1];
                s.Left = shape.Left;
                s.Top  = shape.Top + (i - 1) * shape.Height;
                // Go through paragraphs in new shape and only keep the one we are interested in
                for (int p = n; p > 0; p--)
                {
                    if (i != p)
                    {
                        s.TextFrame2.TextRange.Paragraphs[p].Delete();
                    }
                }
                // Remove line break
                trimNewline(s.TextFrame2.TextRange.Paragraphs[1]);
            }
            // Remove paragraphs 2 - n from original
            for (int p = 2; p <= n; p++)
            {
                shape.TextFrame2.TextRange.Paragraphs[2].Delete();
            }
            // Remove last empty line from original shape
            trimNewline(shape.TextFrame2.TextRange.Paragraphs[1]);
        }
示例#31
0
        private void button1_Click(object sender, EventArgs e)
        {
            PowerPoint.Selection sel = app.ActiveWindow.Selection;
            if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
            {
                PowerPoint.ShapeRange range = sel.ShapeRange;
                if (sel.HasChildShapeRange)
                {
                    range = sel.ChildShapeRange;
                }
                float lm     = app.ActivePresentation.PageSetup.SlideWidth / 2;
                float tm     = app.ActivePresentation.PageSetup.SlideHeight / 2;
                float radius = float.Parse(textBox3.Text.Trim()) * 72 / 2.54f;
                float start  = float.Parse(textBox4.Text.Trim());
                float end    = float.Parse(textBox5.Text.Trim());
                if (range.Count > 1)
                {
                    int   count = range.Count;
                    float angle = (end - start) / (count - 1);
                    for (int i = 0; i < count; i++)
                    {
                        double na = start + angle * i;
                        if (!checkBox1.Checked)
                        {
                            na = start + 360 - angle * i;
                        }
                        double nx = lm - Math.Cos(na * (float)Math.PI / 180) * radius;
                        double ny = tm - Math.Sin(na * (float)Math.PI / 180) * radius;
                        range[i + 1].Left = (float)nx - range[i + 1].Width / 2;
                        range[i + 1].Top  = (float)ny - range[i + 1].Height / 2;
                    }
                }
                else
                {
                    float            angle  = float.Parse(textBox6.Text.Trim());
                    double           na     = start + angle;
                    PowerPoint.Shape nshape = range[1].Duplicate()[1];
                    if (!checkBox1.Checked)
                    {
                        na = start + 360 - angle;
                    }
                    textBox4.Text = na.ToString();
                    double nx0 = lm - Math.Cos(start * (float)Math.PI / 180) * radius;
                    double ny0 = tm - Math.Sin(start * (float)Math.PI / 180) * radius;
                    range[1].Left = (float)nx0 - range[1].Width / 2;
                    range[1].Top  = (float)ny0 - range[1].Height / 2;

                    double nx = lm - Math.Cos(na * (float)Math.PI / 180) * radius;
                    double ny = tm - Math.Sin(na * (float)Math.PI / 180) * radius;
                    nshape.Left = (float)nx - nshape.Width / 2;
                    nshape.Top  = (float)ny - nshape.Height / 2;
                    nshape.Select();
                }
            }
            else
            {
                MessageBox.Show("请先选中图形");
            }
        }
 public static void Init(PowerPoint.Application application)
 {
     if (!isInit)
     {
         isInit = true;
         application.WindowSelectionChange += (selection) =>
         {
             selectedRange = selection;
             if (!IsHookSuccessful())
             {
                 IntPtr PPHandle = Process.GetCurrentProcess().MainWindowHandle;
                 StartHook(PPHandle);
             }
         };
     }
 }