Drawing3d documented Class Library

TaskCtrl.Commit(Int32, String, Object) Method

The handling of the undo- redo-theme seems to be easier with this method than with Commit. You specify the rollbackdata in the object UndoData. This object you get back in the UnDo method or in the event OnUndo.
The id is a tag, which you have to choice for every rollback situation. For example if you want to rollback "Insert" "Delete" and "Update" you define

const int UD_Insert = 1;
const int UD_Delete = 2;
const int UD_Update = 3;
and call
 Commit(UD_Insert,"Insert an object",UDData);
 ....
 and 
 ....
 public override void UnDo(int id, object Data)
 {
   UndoData UD = (Data as UndoData);

    switch (id)
    {
    case  UD_Insert: RemoveCustomerAt(UD.Id);
                    break;
    case  UD_Delete: InsertCustomer(UD.Id, UD.Name, UD.Street, UD.Country);
                 break;
    case  UD_Update: UpdateCustomerAt(UD.Id, UD.Name, UD.Street, UD.Country);
                 break;
                 
 
 
    }
 }
 ...
 where
 ...
 public void RemoveCustomerAt(int Id)
  {
 
    Commit(UD_Delete, "Delete Customer", new UndoData(Id, Form1.CustomerContainer[Id]));
    CustomerContainer.RemoveAt(Id);
  }
  ...
  public  Customer InsertCustomer(int id,string Name, string Street, string Country)
  {
    Customer Result = new Customer(Name, Street, Country);
    Commit(UD_Insert, "Add Customer", new UndoData(id,Result));
    CustomerContainer.Insert(id,Result);
    return Result;
  }
  ...
  and
  ...
   public void UpdateCustomerAt(int Id, string Name, string Street, string Country)
{
    Customer C = CustomerContainer[Id];
    Commit(UD_Update, "Update Customer", new UndoData(Id,C));
    C.Name = Name;
    C.Street = Street;
    C.Country = Country;
}
 
To start Undo you call for example in a click event UnDo resp. ReDoCommit

[Visual Basic]
Public Overloads Sub Commit( _
   ByVal id As Integer, _
   ByVal Text As String, _
   ByVal UndoData As Object _
)
[C#]
public void Commit(
   int id,
   string Text,
   object UndoData
);

Parameters

id
Specifies the context of undoing.
Text
Specifies the text, which can be drawn in a list containing "undos"
UndoData
Specifies the data, which are needed to recontruct the original context.

See Also

TaskCtrl Class | Drawing3d Namespace | TaskCtrl.Commit Overload List