private void OnDeleteCustomControl(object sender, EventArgs e)
{
if ((_ribbonCustomControl != null) && (_ribbonCustomControl.Ribbon != null))
{
// Get access to the parent collection of items
TypedRestrictCollection<KryptonRibbonGroupItem> items = ParentItems;
// Use a transaction to support undo/redo actions
DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCustomControl DeleteCustomControl");
try
{
// Get access to the Items property
MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonCustomControl.RibbonContainer)["Items"];
// Remove the ribbon group from the ribbon tab
RaiseComponentChanging(null);
RaiseComponentChanging(propertyItems);
// Remove the custom control from the group
items.Remove(_ribbonCustomControl);
// Get designer to destroy it
_designerHost.DestroyComponent(_ribbonCustomControl);
RaiseComponentChanged(propertyItems, null, null);
RaiseComponentChanged(null, null, null);
}
finally
{
// If we managed to create the transaction, then do it
if (transaction != null)
transaction.Commit();
}
}
}