System.ComponentModel.Design.DesignerTransaction Class

Provides a way to group a series of design-time actions to improve performance and enable most types of changes to be undone.

See Also: DesignerTransaction Members

Syntax

public abstract class DesignerTransaction : IDisposable

Remarks

Transactions can track actions that can be undone later. Changes made during a transaction can be reversed by canceling a transaction, which automatically attempts to reverse each change by setting each changed property to its pre-change value. Transactions can also improve performance during a series of operations by deferring updates to the display until the completion of the transaction.

When a transaction is in progress, some components defer their processing until the transaction has completed by listening to the IDesignerHost.TransactionOpening and IDesignerHost.TransactionClosed events. The Properties window, for example, does not update its display after a transaction has opened until the transaction has closed.

To use transactions for reversible or multiple operations, have your designer create a System.ComponentModel.Design.DesignerTransaction for each operation or series of operations which should be reversible. Be careful not to perform actions outside the transactions that might prevent a sequence of undo events from completing successfully.

You can obtain a new System.ComponentModel.Design.DesignerTransaction by calling the IDesignerHost.CreateTransaction method of an System.ComponentModel.Design.IDesignerHost. Be sure to obtain each System.ComponentModel.Design.DesignerTransaction from the active System.ComponentModel.Design.IDesignerHost in order to correctly integrate with the designer transaction processing mechanism, rather than creating a new System.ComponentModel.Design.DesignerTransaction directly.

To perform an action within a transaction, you must first create a transaction. Then you must call the IComponentChangeService.OnComponentChanging(object, System.ComponentModel.MemberDescriptor) method before each change or set of changes occurs, and the IComponentChangeService.OnComponentChanged(object, System.ComponentModel.MemberDescriptor, object, object) method after each change or set of changes occur. Finally, complete and close the transaction by calling the DesignerTransaction.Commit method.

Note:

When making changes to property values, use the System.ComponentModel.PropertyDescriptor.SetValue(object, object) method of a System.ComponentModel.PropertyDescriptor, which calls the component change methods of the System.ComponentModel.Design.IComponentChangeService and creates a System.ComponentModel.Design.DesignerTransaction representing the change automatically.

To perform a transaction, complete the following steps:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

In C#, you can use the using statement rather than a try/finally block, such as in the following example.

Example

 using (host.CreateTransaction() {
 // Insert your code here.
 }

To cancel and attempt to roll back a transaction before it has been committed, call the DesignerTransaction.Cancel method. When the DesignerTransaction.Cancel method is invoked, the actions tracked by the System.ComponentModel.Design.DesignerTransaction are reversed to attempt to roll back the changes. To undo actions that occurred as part of earlier transactions, you must use the undo command provided by the development environment.

Requirements

Namespace: System.ComponentModel.Design
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0, 4.0.0.0