コード例 #1
0
        /// <summary>
        /// Attach control as child of control
        /// </summary>
        /// <param name="child">Child control</param>
        /// <param name="atback">False, at front of Z order, True, at back</param>
        public virtual void Add(GLBaseControl child, bool atback = false)
        {
            System.Diagnostics.Debug.Assert(!childrenz.Contains(child)); // no repeats
            child.parent             = this;
            child.suspendLayoutCount = 0;                                // we unsuspend - controls are created suspended

            child.ClearFlagsDown();                                      // in case of reuse, clear all temp flags as child is added

            if (atback)
            {
                childrenz.Add(child);
                childreniz.Insert(0, child);
            }
            else
            {
                int ipos = 0;
                if (!child.TopMost)                                           // add at end of top list.
                {
                    while (ipos < childrenz.Count && childrenz[ipos].TopMost) // find first place we can insert
                    {
                        ipos++;
                    }
                }

                childrenz.Insert(ipos, child);                     // in z order.  First is top of z.  insert puts it before existing
                childreniz.Insert(childreniz.Count - ipos, child); // in inv z order. Last is top of z.  if ipos=0, at end. if ipos=1, inserted just before end
            }

            CheckZOrder();      // verify its okay

            if (EnableThemer)
            {
                Themer?.Invoke(child);      // global themer
            }
            OnControlAdd(this, child);
            child.OnControlAdd(this, child);
            InvalidateLayout(child);        // we are invalidated and layout due to this child
        }