コード例 #1
0
        /// <summary>
        /// Provides a routine which merges a container with its parent (if appropriate).
        /// The purpose of this logic is to remove internally created containers when they are not needed.
        /// </summary>
        protected internal virtual bool MergeWithParentContainer()
        {
            this.UpdateCollapsed();
            //only internally created split containers are target of automatic clean-up
            if (!this.isCleanUpTarget)
            {
                return(false);
            }

            if (this.panels.Count == 0)
            {
                this.Dispose();
                return(true);
            }

            RadSplitContainer parentContainer = this.Parent as RadSplitContainer;

            if (parentContainer == null)
            {
                return(false);
            }

            //we have one child panel, add it to our parent
            if (this.panels.Count == 1)
            {
                //remember at which position are we and what size we have
                int  index    = parentContainer.SplitPanels.IndexOf(this);
                Size currSize = this.Size;

                //detach ourselves from the parent
                this.Parent = null;
                SplitPanel child = this.panels[0];

                child.Parent = null;
                child.Size   = currSize;

                parentContainer.panels.Insert(index, child);

                return(true);
            }

            //since we are the only child in our parent,
            //we simply remove ourselves and add our children to our parent
            if (parentContainer.SplitPanels.Count == 1)
            {
                //do not forget to get set orientation for the container we are merging with
                parentContainer.Orientation = this.Orientation;
                List <SplitPanel> children = ControlHelper.GetChildControls <SplitPanel>(this, false);
                //remove ourselves from Parent's panels
                this.Parent = null;
                this.SplitPanels.Clear();
                //add all our children to our parent
                foreach (SplitPanel child in children)
                {
                    parentContainer.SplitPanels.Add(child);
                }

                return(true);
            }

            //now check for equal orientation - we do not want nested containers with equal orientation
            if (parentContainer.Orientation == this.orientation)
            {
                //get all our children and add them to the parent container
                int index = parentContainer.SplitPanels.IndexOf(this);
                List <SplitPanel> children = ControlHelper.GetChildControls <SplitPanel>(this, false);

                this.Parent = null;
                this.SplitPanels.Clear();

                foreach (SplitPanel child in children)
                {
                    parentContainer.SplitPanels.Insert(index++, child);
                }

                return(true);
            }

            return(false);
        }