C # Presentation prohibit or allow modification of shapes

Source: Internet
Author: User

After you set the shape properties, you can suppress the editing of certain properties of the shape to achieve the purpose of protecting shape formatting. Common methods are: Lock shapes prohibit selection, and prohibit modification of specific properties of shapes. The former protects all formats of the shape, cannot be selected, and cannot modify any properties. The latter, for specific properties of the shape, such as shape size, position, type, text, rotation, etc., are edited to limit the purpose of protecting certain properties of the shape.

This blog post is intended to introduce the use of our free products spire.presentation, the use of C #, the creation of PPT documents, the addition of setting shapes, and the protection settings for shapes. Welcome everyone from our official website e-iceblue download use free spire.presentation, test these features. When the download is complete, add the. dll of the Bin folder as a reference to Visual Studio.

namespaces to use (namespace):

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

Step One: Create a ppt document and add a rectangle shape.

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

Step Two: format the shape, add text to it, set the text font, color, and alignment.

Shape. Fill. Filltype= Fillformattype. None;Shape. Shapestyle. LineColor. Color= Color. Darkgreen;Shape. TextFrame. Paragraphs[0]. Alignment= Textalignmenttype. Justify;Shape. TextFrame. Text="Demo document: \ nthe Gray section indicates non-editable." The green and black sections represent editable ";Shape. TextFrame. Paragraphs[0]. TextRanges[0]. Latinfont= New Textfont ("in italics");Shape. TextFrame. Paragraphs[0]. TextRanges[0]. Fill. Filltype= Fillformattype. Solid;Shape. TextFrame. Paragraphs[0]. TextRanges[0]. Fill. Solidcolor. Color= Color. Black;

Step Three: use the bool declaration to suppress the changed attributes section. The settings can be selected here, and then the specific property protection items are set.

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;

Step 4: Save the presentation document and start the viewing effect.

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

Run the result diagram:


Full code:

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 ( -, -, the, Max));Shape. Fill. Filltype= Fillformattype. None;Shape. Shapestyle. LineColor. Color= Color. Darkgreen;Shape. TextFrame. Paragraphs[0]. Alignment= Textalignmenttype. Justify;Shape. TextFrame. Text="Demo document: \ nthe Gray section indicates non-editable." The green and black sections represent editable ";Shape. TextFrame. Paragraphs[0]. TextRanges[0]. Latinfont= New Textfont ("in italics");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");}    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C # Presentation prohibit or allow modification of shapes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.