Pen and marker using PowerPoint 2010 interop

I'm new to PowerPoint interop, and I'm trying to draw red pen lines and a yellow text marker (not shapes !!!) in presentation mode.

UPDATE:

I can draw a line like this:

settings = presentation.SlideShowSettings; window = settings.Run(); window.View.DrawLine(startX, startY, endX, endY); 

But the line will always be black and thin. How can I choose a red pen or a yellow text marker?

In addition to the DrawLine method, I can select a pen for the user (the mouse cursor becomes a pen instead of an arrow) by setting:

 window.View.PointerType = PpSlideShowPointerType.ppSlideShowPointerPen; window.View.PointerColor.RGB = 255; 

But how can I set it to a text marker? yellow will be 65535, how do I get a text marker style (larger pen, transparency) instead of a tiny hard pen?

+7
source share
2 answers
  • Create a transparent and top WPF window (EDIT: do not enlarge the window)

     <Window ... Background="#00000000" Topmost="True" ShowInTaskbar="False" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize"> 
  • (NEW) Use GetWindowRect to get the location and size of the slide show window.

     [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); [StructLayout(LayoutKind.Sequential)] private struct RECT { public int Left; public int Top; public int Right; public int Bottom; } 
  • Place a transparent window in a PowerPoint slideshow window

     settings = presentation.SlideShowSettings; slideshowWindow = settings.Run(); RECT rect = new RECT(); GetWindowRect(new IntPtr(slideshowWindow.HWND), ref rect); overlayWindow.Left = rect.Left; // EDIT: do not use slideshowWindow.Left, etc. overlayWindow.Top = rect.Top; overlayWindow.Width = rect.Width; overlayWindow.Height = rect.Height; 
  • Place the canvas in the WPF window and add Polyline objects to it as needed. Text marker lines can be like this:

     line = new Polyline { Opacity = 0.8, Stroke = new SolidColorBrush(Colors.Yellow), StrokeThickness = 20 }; this.canvas.Children.Add(line); 

    Add points to the line. As needed. Call this.canvas.Children.Clear() to clear all your drawings.

This is a workaround, but I would say your best shot.

+3
source

My sample application starts by creating an instance of the PowerPoint.Application class;

PowerPoint.Application PowerPointApplication = new PowerPoint.Application();

Then I set the Visible property to msoTrue ;

 PowerPointApplication.Visible = Core.MsoTriState.msoTrue; 

Then create Presentation and Slide ;

 PowerPoint.Presentations PowerPointPresentationSet = PowerPointApplication.Presentations; PowerPoint._Presentation PowerPointPresentation = PowerPointPresentationSet.Add(); PowerPoint.Slides PowerPointSlideSet = PowerPointPresentation.Slides; PowerPoint._Slide PowerPointSlide = PowerPointSlideSet.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank); 

In my code, I created a Shape object;

 PowerPoint.Shape PowerPointShape = PowerPointSlide.Shapes.AddLine(100, 100, 500, 500); 

Then I format it as follows:

 PowerPointShape.Line.Weight = 10; PowerPointShape.Line.ForeColor.RGB = 65535; PowerPointShape.Line.Transparency = 0.8f; 

Point, Opacity grows when the Transparency property decreases.

You can set the Line.Weight property to reduce or add a line to a line, and you can set the value of the Foreground.RGB property to change the color of the line.

PS: I added a scope for using these files in namespaces,

 using PowerPoint = Microsoft.Office.Interop.PowerPoint; using Core = Microsoft.Office.Core; 

You can find a working solution at this link; http://snipt.org/nsgk7

+2
source

All Articles