C# Presentation 禁止或允許修改形狀

來源:互聯網
上載者:User

標籤:免費ppt控制項   net   c#   

在設定形狀屬性後,可禁止對形狀某些屬性的編輯,以達到保護形狀格式的目的。常用方法有:鎖定形狀禁止選擇, 和禁止對形狀的具體屬性進行修改。前者保護形狀的所有格式,無法選取,無法修改任何屬性。後者,對形狀的具體屬性,例如形狀大小,位置,類型,文本,旋轉等,進行編輯限制,以達到保護形狀某些屬性的目的。

本篇博文,旨在介紹使用我司免費產品,Free Spire.Presentation,使用C#,建立PPT文檔,添加設定形狀,並對形狀進行保護設定。歡迎大家從我司官網E-iceblue下載使用Free Spire.Presentation,測試這些功能。下載完成後,請將bin檔案夾的.dll添加作為Visual Studio的引用。

需要用到的命名空間(namespace):

using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;

步驟一:建立PPT文檔,並添加矩形形狀。

Presentation presentation = new Presentation();IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 450, 150));

步驟二:設定形狀格式,為其添加文本,設定文本字型,顏色,對齊。

shape.Fill.FillType = FillFormatType.None;shape.ShapeStyle.LineColor.Color = Color.DarkGreen;shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;shape.TextFrame.Text = "示範文檔:\n    灰色部分表示不可編輯。    綠色和黑色部分表示可編輯";shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("楷體");shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;

步驟三:利用bool聲明禁止改變的屬性部分。此處設定可選取,然後再對具體屬性保護項進行設定。

shape.Locking.RotationProtection = false;shape.Locking.SelectionProtection = false;shape.Locking.ResizeProtection = true;shape.Locking.PositionProtection = true;shape.Locking.ShapeTypeProtection = true;shape.Locking.AspectRatioProtection = true;shape.Locking.TextEditingProtection = true;shape.Locking.AdjustHandlesProtection = true;

步驟4:儲存presentation文檔,啟動查看效果。

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);System.Diagnostics.Process.Start("result.pptx");

運行結果圖:


完整代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;namespace test{    class Program    {        static void Main(string[] args)        {            Presentation presentation = new Presentation();            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 450, 150));            shape.Fill.FillType = FillFormatType.None;            shape.ShapeStyle.LineColor.Color = Color.DarkGreen;            shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;            shape.TextFrame.Text = "示範文檔:\n    灰色部分表示不可編輯。    綠色和黑色部分表示可編輯";            shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("楷體");            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;            shape.Locking.RotationProtection = false;            shape.Locking.SelectionProtection = false;            shape.Locking.ResizeProtection = true;            shape.Locking.PositionProtection = true;            shape.Locking.ShapeTypeProtection = true;            shape.Locking.AspectRatioProtection = true;            shape.Locking.TextEditingProtection = true;            shape.Locking.AdjustHandlesProtection = true;            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);            System.Diagnostics.Process.Start("result.pptx");        }    }}

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

C# Presentation 禁止或允許修改形狀

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.