private void InsertIntoDropDown(ToolStripDropDown parent, System.Type t) { IDesignerHost host = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost)); int index = parent.Items.IndexOf(this.currentItem); if (parent != null) { ToolStripDropDownItem ownerItem = parent.OwnerItem as ToolStripDropDownItem; if ((ownerItem != null) && ((ownerItem.DropDownDirection == ToolStripDropDownDirection.AboveLeft) || (ownerItem.DropDownDirection == ToolStripDropDownDirection.AboveRight))) { index++; } } IDesigner designer = null; DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("ToolStripAddingItem")); try { IComponent component = host.CreateComponent(t); designer = host.GetDesigner(component); if (designer is ComponentDesigner) { ((ComponentDesigner)designer).InitializeNewComponent(null); } parent.Items.Insert(index, (ToolStripItem)component); ISelectionService service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService)); if (service != null) { service.SetSelectedComponents(new object[] { component }, SelectionTypes.Replace); } } catch (Exception exception) { if (((parent != null) && (parent.OwnerItem != null)) && (parent.OwnerItem.Owner != null)) { ToolStripDesigner designer2 = host.GetDesigner(parent.OwnerItem.Owner) as ToolStripDesigner; if (designer2 != null) { designer2.CancelPendingMenuItemTransaction(); } } this.TryCancelTransaction(ref transaction); if (System.Windows.Forms.ClientUtils.IsCriticalException(exception)) { throw; } } finally { if (transaction != null) { transaction.Commit(); transaction = null; } } }