我是PowerPoint互操作的新手,我正在尝试在演示模式下绘制红笔和黄色文字标记(非形状!!!)行。
更新:
我可以画一条这样的一句话:
settings = presentation.SlideShowSettings;
window = settings.Run();
window.View.DrawLine(startX, startY, endX, endY);
但这条线总是黑而薄。如何为其选择红笔或黄色文字标记?
除了DrawLine方法,我可以通过设置为用户选择笔(鼠标光标变成笔而不是箭头):
window.View.PointerType = PpSlideShowPointerType.ppSlideShowPointerPen;
window.View.PointerColor.RGB = 255;
但是如何将其设置为文本标记?黄色将是65535,如何获得文字标记样式(更大的笔,透明度)而不是微小的实心笔?
答案 0 :(得分:3)
创建一个透明且最顶端的WPF窗口(编辑:不要最大化窗口)
<Window ... Background="#00000000" Topmost="True" ShowInTaskbar="False" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize">
(新)使用GetWindowRect获取幻灯片放映窗口的位置和大小
[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;
}
将透明窗口放在PowerPoint幻灯片窗口
上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;
将Canvas放入WPF窗口,并根据需要向其添加Polyline对象。文字标记线可以是这样的:
line = new Polyline
{
Opacity = 0.8,
Stroke = new SolidColorBrush(Colors.Yellow),
StrokeThickness = 20
};
this.canvas.Children.Add(line);
根据需要为line.Points添加点数。致电this.canvas.Children.Clear()
清除所有图纸。
这是一种解决方法,但我会说你最好的一击。
答案 1 :(得分:2)
我的示例应用程序首先创建一个PowerPoint.Application
类的实例;
PowerPoint.Application PowerPointApplication = new PowerPoint.Application();
然后我将Visible
属性设置为msoTrue
;
PowerPointApplication.Visible = Core.MsoTriState.msoTrue;
然后创建Presentation
和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);
在我的代码中,我创建了一个Shape
对象;
PowerPoint.Shape PowerPointShape = PowerPointSlide.Shapes.AddLine(100, 100, 500, 500);
然后,我这样格式化;
PowerPointShape.Line.Weight = 10;
PowerPointShape.Line.ForeColor.RGB = 65535;
PowerPointShape.Line.Transparency = 0.8f;
关键是,当Opacity
属性减少时,Transparency
会增长。
您可以将Line.Weight
属性设置为 thinner 或 ticker 该行,您可以设置Foreground.RGB
属性的值来更改颜色线。
PS:我添加了这些名称空间代码文件使用区域;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Core = Microsoft.Office.Core;
您可以通过此链接找到有效的解决方案; http://snipt.org/nsgk7