コード例 #1
0
        public static T Create <T>(
            this Control parent,
            AnchorStylesExtended anchor,
            string text,
            bool placeToRight = false,
            int margin        = 8,
            int lineHeight    = 24)
            where T : Control, new()
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }


            var topOffset  = margin;
            var leftOffset = margin;

            var parentForm = parent as Form;

            if (parentForm != null)
            {
                topOffset += parentForm.uwfHeaderHeight;
            }

            var parentControls = parent.Controls;

            if (parentControls.Count > 0)
            {
                Control lastChild = null;
                for (int i = parentControls.Count - 1; i >= 0; i--)
                {
                    var child = parentControls[i];
                    if (child.uwfSystem)
                    {
                        continue;
                    }

                    lastChild = child;
                    break;
                }

                if (lastChild != null)
                {
                    var lastChildY = lastChild.Location.Y;
                    {
                        if (placeToRight)
                        {
                            leftOffset = lastChild.Location.X + lastChild.Width + margin;
                            topOffset  = lastChildY;
                        }
                        else if (lastChildY >= topOffset)
                        {
                            topOffset = lastChildY + lineHeight;
                        }
                    }
                }
            }

            var control = new T();

            control.Anchor   = (AnchorStyles)anchor;
            control.Location = new Point(leftOffset, topOffset);
            control.Text     = text;

            parentControls.Add(control);

            return(control);
        }
コード例 #2
0
 public static T Create <T>(this Control parent, AnchorStylesExtended anchor, bool placeToRight = false, int margin = 8, int lineHeight = 24) where T : Control, new()
 {
     return(Create <T>(parent, anchor, null, placeToRight, margin, lineHeight));
 }