Office中国论坛/Access中国论坛

标题: 【OneKeyTools源代码分享4】二等分线 [打印本页]

作者: 只为设计    时间: 2016-2-28 20:06
标题: 【OneKeyTools源代码分享4】二等分线
本帖最后由 只为设计 于 2016-2-29 19:40 编辑

有时候我们需要在PPT中自定义一些固定的参考线。比如二等分线、黄金分割线、三等分线等。借助编程可以很容易实现。
下面的代码是OneKeyTools中“分割线”→“二等分线”的源代码。

基本代码】↓
  1. PowerPoint.Slide slide = app.ActiveWindow.View.Slide;
  2. PowerPoint.Selection sel = app.ActiveWindow.Selection;
  3. if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
  4. {
  5. float swidth = app.ActivePresentation.PageSetup.SlideWidth;
  6. float sheight = app.ActivePresentation.PageSetup.SlideHeight;
  7. PowerPoint.Shape line1 = slide.Shapes.AddLine(swidth * 0.5f, 0, swidth * 0.5f, sheight);
  8. PowerPoint.Shape line2 = slide.Shapes.AddLine(0, sheight * 0.5f, swidth, sheight * 0.5f);
  9. line1.Visible = Office.MsoTriState.msoTrue;
  10. line2.Visible = Office.MsoTriState.msoTrue;
  11. line1.Name = "line01";
  12. line2.Name = "line01";
  13. if (slide.Background.Fill.ForeColor.RGB > 255 + 200 * 256 + 200 * 256 * 256)
  14. {
  15. line1.Line.ForeColor.RGB = 0;
  16. line2.Line.ForeColor.RGB = 0;
  17. }
  18. else
  19. {
  20. line1.Line.ForeColor.RGB = 255 + 255 * 256 + 255 * 256 * 256;
  21. line2.Line.ForeColor.RGB = 255 + 255 * 256 + 255 * 256 * 256;
  22. }
  23. line1.Line.DashStyle = Office.MsoLineDashStyle.msoLineDash;
  24. line2.Line.DashStyle = Office.MsoLineDashStyle.msoLineDash;
  25. }
复制代码


代码分析】↓
  1. PowerPoint.Slide slide = app.ActiveWindow.View.Slide;
  2. float swidth = app.ActivePresentation.PageSetup.SlideWidth;
  3. float sheight = app.ActivePresentation.PageSetup.SlideHeight;
复制代码
↑这段代码是获取PPT幻灯片页面的宽度和高度,用于算二等分线的具体坐标。


  1. PowerPoint.Shape line1 = slide.Shapes.AddLine(swidth * 0.5f, 0, swidth * 0.5f, sheight);
  2. PowerPoint.Shape line2 = slide.Shapes.AddLine(0, sheight * 0.5f, swidth, sheight * 0.5f);
复制代码
↑这段代码是往页面中添加二等分线。其中AddLine(起始x坐标,起始y坐标,终止x坐标,终止y坐标)。

  1. if (slide.Background.Fill.ForeColor.RGB > 255 + 200 * 256 + 200 * 256 * 256)
复制代码
↑这个判断,是判断幻灯片背景的颜色,如果深色就用白色线;如果背景浅,就用黑色线

  1. line1.Name = "line01";
  2. line2.Name = "line01";
复制代码
↑这是对横竖两条二等分线进行命名,方便后面做删除功能。

上一篇:【PPT纹理】磨砂+牛仔布料+纸质纹理      下一篇:PPT裁图变形1


作者: Xy平面坐标系    时间: 2016-2-28 20:15
来顶顶~
作者: tmtony    时间: 2016-2-29 09:42
谢谢分享!




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3