public void RemoveDesignSurface(DesignSurfaceExt2 surfaceToErase) { try { //- remove the TabPage which has the same name of //- the RootComponent host by DesignSurface "surfaceToErase" //- Note: //- DesignSurfaceManager continues to reference the DesignSurface erased //- that Designsurface continue to exist but it is no more reachable //- this fact is usefull when generate new names for Designsurfaces just created //- avoiding name clashing string dsRootComponentName = surfaceToErase.GetIDesignerHost().RootComponent.Site.Name; TabPage tpToRemove = null; foreach (TabPage tp in this.tbCtrlpDesigner.TabPages) { if (tp.Name == dsRootComponentName) { tpToRemove = tp; break; } //end_if } //end_foreach if (null != tpToRemove) { this.tbCtrlpDesigner.TabPages.Remove(tpToRemove); } //- now remove the DesignSurface this.DesignSurfaceManager.DeleteDesignSurfaceExt2(surfaceToErase); //- finally the DesignSurfaceManager remove the DesignSurface //- AND set as active DesignSurface the last one //- therefore we set as active the last TabPage this.tbCtrlpDesigner.SelectedIndex = this.tbCtrlpDesigner.TabPages.Count - 1; }//end_try catch (Exception exx) { Debug.WriteLine(exx.Message); if (null != exx.InnerException) { Debug.WriteLine(exx.InnerException.Message); } throw; }//end_catch }