|
本帖最后由 只為設計 于 2016-2-29 19:40 編輯
有時候我們需要在PPT中自定義一些固定的參考線。比如二等分線、黃金分割線、三等分線等。借助編程可以很容易實現(xiàn)。
下面的代碼是OneKeyTools中“分割線”→“二等分線”的源代碼。
【基本代碼】↓
- PowerPoint.Slide slide = app.ActiveWindow.View.Slide;
- PowerPoint.Selection sel = app.ActiveWindow.Selection;
- if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
- {
- float swidth = app.ActivePresentation.PageSetup.SlideWidth;
- float sheight = app.ActivePresentation.PageSetup.SlideHeight;
- PowerPoint.Shape line1 = slide.Shapes.AddLine(swidth * 0.5f, 0, swidth * 0.5f, sheight);
- PowerPoint.Shape line2 = slide.Shapes.AddLine(0, sheight * 0.5f, swidth, sheight * 0.5f);
- line1.Visible = Office.MsoTriState.msoTrue;
- line2.Visible = Office.MsoTriState.msoTrue;
- line1.Name = "line01";
- line2.Name = "line01";
- if (slide.Background.Fill.ForeColor.RGB > 255 + 200 * 256 + 200 * 256 * 256)
- {
- line1.Line.ForeColor.RGB = 0;
- line2.Line.ForeColor.RGB = 0;
- }
- else
- {
- line1.Line.ForeColor.RGB = 255 + 255 * 256 + 255 * 256 * 256;
- line2.Line.ForeColor.RGB = 255 + 255 * 256 + 255 * 256 * 256;
- }
- line1.Line.DashStyle = Office.MsoLineDashStyle.msoLineDash;
- line2.Line.DashStyle = Office.MsoLineDashStyle.msoLineDash;
- }
復制代碼
【代碼分析】↓
- PowerPoint.Slide slide = app.ActiveWindow.View.Slide;
- float swidth = app.ActivePresentation.PageSetup.SlideWidth;
- float sheight = app.ActivePresentation.PageSetup.SlideHeight;
復制代碼 ↑這段代碼是獲取PPT幻燈片頁面的寬度和高度,用于算二等分線的具體坐標。
- PowerPoint.Shape line1 = slide.Shapes.AddLine(swidth * 0.5f, 0, swidth * 0.5f, sheight);
- PowerPoint.Shape line2 = slide.Shapes.AddLine(0, sheight * 0.5f, swidth, sheight * 0.5f);
復制代碼 ↑這段代碼是往頁面中添加二等分線。其中AddLine(起始x坐標,起始y坐標,終止x坐標,終止y坐標)。
- if (slide.Background.Fill.ForeColor.RGB > 255 + 200 * 256 + 200 * 256 * 256)
復制代碼 ↑這個判斷,是判斷幻燈片背景的顏色,如果深色就用白色線;如果背景淺,就用黑色線
- line1.Name = "line01";
- line2.Name = "line01";
復制代碼 ↑這是對橫豎兩條二等分線進行命名,方便后面做刪除功能。
|
|