예제 #1
0
        public void Activate()
        {
            TabPageSwitcher tabPageSwitcher = this.Parent as TabPageSwitcher;

            if (tabPageSwitcher != null)
            {
                tabPageSwitcher.SelectedControl = this;
            }
        }
예제 #2
0
            public override void SetChildIndex(Control child, int newIndex)
            {
                if (newIndex == Count - 1)
                {
                    TabPageSwitcher parent = Owner as TabPageSwitcher;
                    if (parent != null && parent.SelectedControl != null && parent.SelectedControl != child)
                    {
                        base.SetChildIndex(child, Math.Max(0, newIndex - 1));
                    }
                }

                base.SetChildIndex(child, newIndex);
            }
        protected override IComponent[] CreateComponentsCore(IDesignerHost host)
        {
            IComponent[] components = base.CreateComponentsCore(host);

            Control                 parentControl         = null;
            ControlDesigner         parentControlDesigner = null;
            TabStrip                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 TabStrip)
            {
                tabStrip = components[0] as TabStrip;

                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;
                    }
                    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);
                    }

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

                    SetProperties(controlSwitcher, propertyValues, host);
                }
                finally {
                    if (t != null)
                    {
                        t.Commit();
                    }
                }

                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);
        }