(Leadtools.Annotations.Automation)

BeginUndo Method

Show in webframe
Example 




Creates a new undo node in this AnnAutomation object.
Syntax
public virtual void BeginUndo()
public virtual void BeginUndo()
-(void) beginUndo;
public void beginUndo()
 function Leadtools.Annotations.Automation.AnnAutomation.BeginUndo()
Remarks

Use BeginUndo, EndUndo and CancelUndo to programmatically add a node to the undo stack maintained by this AnnAutomation. Typically, you add an undo node as follows:

  1. Call the BeginUndo method before you make any changes to create a new node.

  2. Perform any changes to the AnnAutomation object.

  3. Call the EndUndo method to commit this undo node into the undo stack of the AnnAutomation object.

  4. In case of errors (typically in a catch statement), call the CancelUndo method to remove the node and cancel the operation.

You do not need to manually call BeginUndo, EndUndo or CancelUndo when calling methods from this AnnAutomation object. The AnnAutomation object will internally do this for you. For example, when you call the DeleteSelectedObjects method to delete the object(s) currently being edited, the AnnAutomation object will perform the above sequence internally to add the undo node.

Use the UndoCapacity property to get or set the number of user actions that can be reversed using the Undo method, or re-applied using the Redo method. The default for the UndoCapacity property is 10 actions.

For information on undoing or redoing automation operations, refer to Undoing Annotation Automation Operations.

Example
Copy Code  
using Leadtools.Annotations.Automation;
using Leadtools.Annotations.Core;
using Leadtools.Codecs;
using Leadtools.WinForms;

public void AnnAutomation_BeginUndo()
{
   // first create a new undo node
   _automation.BeginUndo();
   try
   {
      // add a new rectangle object
      AnnRectangleObject rectObj = new AnnRectangleObject();
      rectObj.Rect = LeadRectD.Create(100, 100, 800, 800);
      rectObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), LeadLengthD.Create(1));
      rectObj.Fill = AnnSolidColorBrush.Create("Yellow");
      _automation.Container.Children.Add(rectObj);

      // Invalidate it
      _automation.Invalidate(LeadRectD.Empty);

      // Select this object
      _automation.SelectObject(rectObj);

      // commit the undo node
      _automation.EndUndo();
   }
   catch (Exception ex)
   {
      // in case of errors, cancel the undo node
      _automation.CancelUndo();
      Debug.WriteLine(ex.Message);
      return;
   }

   Debug.WriteLine("Object has been added as is now selected. Next will call //Undo// to undo the operation");
   _automation.Undo();
   Debug.WriteLine("Operation has been undone. Next will call //Redo// to redo the operation");
   _automation.Redo();
   Debug.WriteLine("Object should be back and selected");
}
using Leadtools.Annotations.Automation;
using Leadtools.Controls;
using Leadtools.Converters;
using Leadtools.Annotations.Core;
using Leadtools.Codecs;

[TestMethod]
public void AnnAutomation_BeginUndo()
{
   // first create a new undo node
   _automation.BeginUndo();
   try
   {
      // add a new rectangle object
      AnnRectangleObject rectObj = new AnnRectangleObject();
      rectObj.Rect = LeadRectDHelper.Create(100, 100, 800, 800);
      rectObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), LeadLengthDHelper.Create(1));
      rectObj.Fill = AnnSolidColorBrush.Create("Yellow");
      _automation.Container.Children.Add(rectObj);

      // Invalidate it
      _automation.Invalidate(LeadRectDHelper.Empty);

      // Select this object
      _automation.SelectObject(rectObj);

      // commit the undo node
      _automation.EndUndo();
   }
   catch (Exception ex)
   {
      // in case of errors, cancel the undo node
      _automation.CancelUndo();
      Debug.WriteLine(ex.Message);
      return;
   }

   Debug.WriteLine("Object has been added as is now selected. Next will call //Undo// to undo the operation");
   _automation.Undo();
   Debug.WriteLine("Operation has been undone. Next will call //Redo// to redo the operation");
   _automation.Redo();
   Debug.WriteLine("Object should be back and selected");
}
Requirements

Target Platforms

See Also

Reference

AnnAutomation Class
AnnAutomation Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.