public void RemovePanel()
{
int oldIndex = this.layout.ExpandedPanelIndex;
if (this.layout.ExpandedPanelIndex > -1)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if (host != null)
{
using (DesignerTransaction dt = host.CreateTransaction("Remove Panel"))
{
IComponentChangeService changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
PanelBase panel = this.layout.Items[oldIndex] as PanelBase;
try
{
changeService.OnComponentChanging(this.layout, TypeDescriptor.GetProperties(this.layout)["Items"]);
this.layout.Items.Remove(panel);
if (this.layout.Items.Count > 0)
{
PanelBase activeItem =
this.layout.Items[Math.Min(oldIndex, this.layout.Items.Count - 1)] as PanelBase;
this.ExpandItem(activeItem);
}
}
finally
{
changeService.OnComponentChanged(this.layout, TypeDescriptor.GetProperties(this.layout)["Items"], null, null);
}
panel.Dispose();
this.UpdateDesignTimeHtml();
dt.Commit();
}
this.Tag.SetDirty(true);
}
}
}