7
votes

I'm new to PowerPoint interop and I'm trying to draw red pen and yellow text marker (not shapes!!!) lines while 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 select the red pen or yellow text marker for it?

Aside from the DrawLine method, I can select the pen for the user (mouse cursor becomes a pen instead of arrow) by setting:

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

But how can I set it to text marker? yellow would be 65535, how do I get the text marker style (bigger pen, transparency) instead of the tiny solid pen?

2
If there's only one slideshow window, wouldn't it be SlideShowWindows[0]?qJake
I tried [0] but it resulted in an exception telling me I should pick an index between 1 and 1 ... so apparently it's not zero based ...Hinek
Ppl, bounty is ending soon, is there really no way to do this?Hinek

2 Answers

3
votes
  1. Create a WPF window that is transparent and topmost (EDIT: do not maximize window)

    <Window ... Background="#00000000" Topmost="True" ShowInTaskbar="False" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize">
    
  2. (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;
    }
    
  3. Place the transparent window over the 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;
    
  4. Put a Canvas into the WPF window and add Polyline objects to it as needed. Text marker lines could be like this:

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

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

It's a workaround but I'd say your best shot.

2
votes

My sample application begins with creating an instance of a PowerPoint.Application class;

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

Then I set Visible property to msoTrue;

PowerPointApplication.Visible = Core.MsoTriState.msoTrue;

Then create a 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 like this;

PowerPointShape.Line.Weight = 10;
PowerPointShape.Line.ForeColor.RGB = 65535;

PowerPointShape.Line.Transparency = 0.8f;

The point is, Opacity grows when Transparency property decreases.

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

PS: I added these namespaces code files usings area;

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

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