Esempio n. 1
0
        /// <summary>
        /// Bring this TabStripPage to the front of the switcher.
        /// </summary>
        public void Activate()
        {
            TabPageSwitcher tabPageSwitcher = this.Parent as TabPageSwitcher;

            if (tabPageSwitcher != null)
            {
                tabPageSwitcher.SelectedTabStripPage = this;

                try
                {
                    int x0 = tabPageSwitcher.TabStrip.SelectedTab.Bounds.Location.X;
                    int xf = tabPageSwitcher.TabStrip.SelectedTab.Bounds.Right;
                    tabPageSwitcher.SelectedTabStripPage.LinePos(x0, xf, true);
                }
                catch { }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// this method is called when dragging a TabStrip off the toolbox.
        /// </summary>
        /// <param name="host">The <see cref="T:System.ComponentModel.Design.IDesignerHost" /> to host the toolbox item.</param>
        /// <returns>An array of created <see cref="T:System.ComponentModel.IComponent" /> objects.</returns>
        protected override IComponent[] CreateComponentsCore(IDesignerHost host)
        {
            IComponent[] components = base.CreateComponentsCore(host);

            Control                 parentControl         = null;
            ControlDesigner         parentControlDesigner = null;
            ZeroitTabStrip          tabStrip  = null;
            IComponentChangeService changeSvc = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));


            // fish out the parent we're adding the TabStrip to.
            if (components.Length > 0 && components[0] is ZeroitTabStrip)
            {
                tabStrip = components[0] as ZeroitTabStrip;

                ITreeDesigner tabStripDesigner = host.GetDesigner(tabStrip) as ITreeDesigner;
                parentControlDesigner = tabStripDesigner.Parent as ControlDesigner;
                if (parentControlDesigner != null)
                {
                    parentControl = parentControlDesigner.Control;
                }
            }

            // Create a ControlSwitcher on the same parent.

            if (host != null)
            {
                TabPageSwitcher controlSwitcher = null;

                DesignerTransaction t = null;
                try {
                    try {
                        t = host.CreateTransaction("add tabswitcher");
                    }
                    catch (CheckoutException ex) {
                        if (ex == CheckoutException.Canceled)
                        {
                            return(components);
                        }
                        throw ex;
                    }

                    // create a TabPageSwitcher and add it to the same parent as the TabStrip
                    MemberDescriptor controlsMember = TypeDescriptor.GetProperties(parentControlDesigner)["Controls"];
                    controlSwitcher = host.CreateComponent(typeof(TabPageSwitcher)) as TabPageSwitcher;

                    if (changeSvc != null)
                    {
                        changeSvc.OnComponentChanging(parentControl, controlsMember);
                        changeSvc.OnComponentChanged(parentControl, controlsMember, null, null);
                    }

                    // specify default values for our TabStrip
                    Dictionary <string, object> propertyValues = new Dictionary <string, object>();
                    propertyValues["Location"] = new Point(tabStrip.Left, tabStrip.Bottom + 3);
                    propertyValues["TabStrip"] = tabStrip;

                    // set the property values
                    SetProperties(controlSwitcher, propertyValues, host);
                }
                finally {
                    if (t != null)
                    {
                        t.Commit();
                    }
                }

                // add the TabPageSwitcher to the list of components that we've created
                if (controlSwitcher != null)
                {
                    IComponent[] newComponents = new IComponent[components.Length + 1];
                    Array.Copy(components, newComponents, components.Length);
                    newComponents[newComponents.Length - 1] = controlSwitcher;
                    return(newComponents);
                }
            }

            return(components);
        }