設為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 2897|回復: 2
打印 上一主題 下一主題

【OneKeyTools源代碼分享4】二等分線

[復制鏈接]
跳轉到指定樓層
1#
發(fā)表于 2016-2-28 20:06:00 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最后由 只為設計 于 2016-2-29 19:40 編輯

有時候我們需要在PPT中自定義一些固定的參考線。比如二等分線、黃金分割線、三等分線等。借助編程可以很容易實現(xiàn)。
下面的代碼是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";
復制代碼
↑這是對橫豎兩條二等分線進行命名,方便后面做刪除功能。


本帖被以下淘專輯推薦:

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖1 訂閱訂閱

點擊這里給我發(fā)消息

2#
發(fā)表于 2016-2-28 20:15:28 | 只看該作者
來頂頂~
回復

使用道具 舉報

點擊這里給我發(fā)消息

3#
發(fā)表于 2016-2-29 09:42:03 | 只看該作者
謝謝分享!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2025-7-17 05:45 , Processed in 0.094648 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表