Пример #1
0
        /// <include file='doc\ToolboxItem.uex' path='docs/doc[@for="ToolboxItem.CreateComponentsCore1"]/*' />
        /// <devdoc>
        ///     Creates objects from the type contained in this toolbox item.  If designerHost is non-null
        ///     this will also add them to the designer.
        /// </devdoc>
        protected virtual IComponent[] CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
        {
            IComponent[] components = CreateComponentsCore(host);

            if (host != null)
            {
                for (int i = 0; i < components.Length; i++)
                {
                    IComponentInitializer init = host.GetDesigner(components[i]) as IComponentInitializer;
                    if (init != null)
                    {
                        bool removeComponent = true;

                        try {
                            init.InitializeNewComponent(defaultValues);
                            removeComponent = false;
                        }
                        finally
                        {
                            if (removeComponent)
                            {
                                for (int index = 0; index < components.Length; index++)
                                {
                                    host.DestroyComponent(components[index]);
                                }
                            }
                        }
                    }
                }
            }

            return(components);
        }
Пример #2
0
        /// <summary>
        /// Creates objects from the type contained in this toolbox item.  If designerHost is non-null
        /// this will also add them to the designer.
        /// </summary>
        protected virtual IComponent[] CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
        {
            IComponent[] components = CreateComponentsCore(host);

            if (host != null)
            {
                for (int i = 0; i < components.Length; i++)
                {
                    IComponentInitializer init = host.GetDesigner(components[i]) as IComponentInitializer;
                    if (init != null)
                    {
                        try
                        {
                            init.InitializeNewComponent(defaultValues);
                        }
                        catch
                        {
                            for (int index = 0; index < components.Length; index++)
                            {
                                host.DestroyComponent(components[index]);
                            }
                            throw;
                        }
                    }
                }
            }

            return(components);
        }
Пример #3
0
 protected virtual IComponent[] CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
 {
     IComponent[] componentArray = this.CreateComponentsCore(host);
     if (host != null)
     {
         for (int i = 0; i < componentArray.Length; i++)
         {
             IComponentInitializer designer = host.GetDesigner(componentArray[i]) as IComponentInitializer;
             if (designer != null)
             {
                 bool flag = true;
                 try
                 {
                     designer.InitializeNewComponent(defaultValues);
                     flag = false;
                 }
                 finally
                 {
                     if (flag)
                     {
                         for (int j = 0; j < componentArray.Length; j++)
                         {
                             host.DestroyComponent(componentArray[j]);
                         }
                     }
                 }
             }
         }
     }
     return(componentArray);
 }
        /// <inheritdoc />
        public void Adapt(object component)
        {
            _componentInitializer = (IComponentInitializer)component;

            _componentInitializer.Starting += OnStarting;
            _componentInitializer.InitializingComponent += OnInitializingComponent;
        }
Пример #5
0
 protected virtual IComponent[] CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
 {
     IComponent[] components = CreateComponentsCore(host);
     foreach (var c in components)
     {
         IComponentInitializer initializer = host.GetDesigner(c) as IComponentInitializer;
         initializer.InitializeNewComponent(defaultValues);
     }
     return(components);
 }
Пример #6
0
        bool IOleDragClient.AddComponent(IComponent component, string name, bool firstAdd)
        {
            IContainer container = base.Component.Site.Container;

            if (((container != null) && (name != null)) && (container.Components[name] != null))
            {
                name = null;
            }
            IContainer container2 = null;
            bool       flag       = false;

            if (!firstAdd)
            {
                if (component.Site != null)
                {
                    container2 = component.Site.Container;
                    if (container2 != container)
                    {
                        container2.Remove(component);
                        flag = true;
                    }
                }
                if (container2 != container)
                {
                    container.Add(component, name);
                }
            }
            if (flag)
            {
                IDesignerHost service = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                if (service != null)
                {
                    IComponentInitializer designer = service.GetDesigner(component) as IComponentInitializer;
                    if (designer != null)
                    {
                        designer.InitializeExistingComponent(null);
                    }
                }
            }
            if (container2 == container)
            {
                return(!firstAdd);
            }
            return(true);
        }