←Select platform

Lock Method (AnnObject)

Summary

Locks this AnnObject with the specified password.

Syntax

C#
VB
Java
Objective-C
WinRT C#
public virtual void Lock(  
   string password 
) 
Public Overridable Sub Lock( _ 
   ByVal password As String _ 
) 
public virtual void Lock(  
   string password 
) 
-(void) lock:(NSString*)password;
public void lock(String password)
function Leadtools.Annotations.Core.AnnObject.Lock(  
   password  
) 

Parameters

password
String containing the password used to lock the annotation object.

Remarks

Only unlocked objects can be locked. If an object is already locked, it will stay locked with its original password. You must pass the same password to Unlock to unlock this AnnObject.

If this method succeeds, password will be stored inside the object and can be retrieved with the Password property.

An object must be unlocked in order to change that object in automated mode.

For more information, refer to Implementing Annotation Security.

Example

C#
WinRT C#
using Leadtools.Annotations.Automation; 
using Leadtools.Annotations.Core; 
using Leadtools.Codecs; 
using Leadtools.Annotations.WinForms; 
 
       
public void AnnObject_Lock() 
{ 
   double inch = 720.0; 
   // Get the container 
   AnnContainer container = _automation.Container; 
 
   // Add the lock picture to the container resources 
 
   // Create a new instance of AnnResources if the container does not already have one 
   AnnResources resources = _automation.Manager.Resources; 
   if (resources == null) 
   { 
      resources = new AnnResources(); 
   } 
 
   // Get the images collection 
   IList<AnnPicture> imagesResources = resources.Images; 
 
   // Add our picture to it 
   imagesResources.Add(new AnnPicture(@"ms-appx:///Assets/Lock.png")); 
   int pictureIndex = imagesResources.Count - 1; 
 
   // Add a blue on yellow rectangle from 3in 3in to 4in 4in 
   AnnRectangleObject rectObj = new AnnRectangleObject(); 
   rectObj.Rect = LeadRectD.Create(3 * inch, 3 * inch, 1 * inch, 1 * inch); 
   rectObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), LeadLengthD.Create(1)); 
   rectObj.Fill = AnnSolidColorBrush.Create("Yellow"); 
 
   // Set its lock picture 
   rectObj.LockPicture = pictureIndex; 
 
   // Add it to the container 
   container.Children.Add(rectObj); 
 
   // Show the object lock state (default) 
   Debug.WriteLine("Default lock state"); 
   ShowLockedState(rectObj); 
 
   // Lock it with a password 
   Debug.WriteLine("Locking now with a password"); 
   rectObj.Lock("secret"); 
 
   // Show the object lock state, it should say locked and the object should be painted with the lock picture 
   ShowLockedState(rectObj); 
 
   // Now try to unlock it with a wrong password 
   Debug.WriteLine("Unlocking with a wrong password"); 
   rectObj.Unlock("wrong password"); 
 
   // Check again, it should still be locked 
   ShowLockedState(rectObj); 
 
   // Finally unlock it with the correct password 
   Debug.WriteLine("Unlocking with a correct password"); 
   rectObj.Unlock("secret"); 
 
   // Check again, it should still be unlocked 
   ShowLockedState(rectObj); 
} 
 
private void ShowLockedState(AnnObject annObj) 
{ 
   _automation.Invalidate(LeadRectD.Empty); 
 
   // Show the object lock state (default) 
   Debug.WriteLine("Locked: " + annObj.IsLocked); 
} 
using Leadtools.Converters; 
using Leadtools.Annotations.Automation; 
using Leadtools.Controls; 
using Leadtools.Annotations.Core; 
using Leadtools.Codecs; 
 
       
public void AnnObject_Lock() 
{ 
   double inch = 720.0; 
   // Get the container 
   AnnContainer container = _automation.Container; 
 
   // Add the lock picture to the container resources 
 
   // Create a new instance of AnnResources if the container does not already have one 
   AnnResources resources = _automation.Container.Resources; 
   if (resources == null) { 
      resources = new AnnResources(); 
      _automation.Container.Resources = resources; 
   } 
 
   // Get the images collection 
   IList<AnnPicture> imagesResources = resources.Images; 
 
   // Add our picture to it 
   imagesResources.Add(new AnnPicture(@"ms-appx:///Assets/Lock.png")); 
   int pictureIndex = imagesResources.Count - 1; 
 
   // Add a blue on yellow rectangle from 3in 3in to 4in 4in 
   AnnRectangleObject rectObj = new AnnRectangleObject(); 
   rectObj.Rect = LeadRectDHelper.Create(3 * inch, 3 * inch, 1 * inch, 1 * inch); 
   rectObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), LeadLengthDHelper.Create(1)); 
   rectObj.Fill = AnnSolidColorBrush.Create("Yellow"); 
 
   // Set its lock picture 
   rectObj.LockPicture = pictureIndex; 
 
   // Add it to the container 
   container.Children.Add(rectObj); 
 
   // Show the object lock state (default) 
   Debug.WriteLine("Default lock state"); 
   ShowLockedState(rectObj); 
 
   // Lock it with a password 
   Debug.WriteLine("Locking now with a password"); 
   rectObj.Lock("secret"); 
 
   // Show the object lock state, it should say locked and the object should be painted with the lock picture 
   ShowLockedState(rectObj); 
 
   // Now try to unlock it with a wrong password 
   Debug.WriteLine("Unlocking with a wrong password"); 
   rectObj.Unlock("wrong password"); 
 
   // Check again, it should still be locked 
   ShowLockedState(rectObj); 
 
   // Finally unlock it with the correct password 
   Debug.WriteLine("Unlocking with a correct password"); 
   rectObj.Unlock("secret"); 
 
   // Check again, it should still be unlocked 
   ShowLockedState(rectObj); 
} 
 
private void ShowLockedState(AnnObject annObj) 
{ 
   _automation.Invalidate(LeadRectDHelper.Empty); 
 
   // Show the object lock state (default) 
   Debug.WriteLine("Locked: " + annObj.IsLocked); 
} 

Requirements

Target Platforms

See Also

Reference

AnnObject Class

AnnObject Members

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Leadtools.Annotations.Core Assembly
Click or drag to resize