예제 #1
0
        public static void SetDock(IArrangedElement element, DockStyle value)
        {
            Debug.Assert(!HasCachedBounds(element.Container), "Do not call this method with an active cached bounds list.");

            if (GetDock(element) != value)
            {
                SourceGenerated.EnumValidator.Validate(value);

                bool dockNeedsLayout = CommonProperties.GetNeedsDockLayout(element);
                CommonProperties.xSetDock(element, value);

                using (new LayoutTransaction(element.Container as Control, element, PropertyNames.Dock))
                {
                    // if the item is autosized, calling setbounds performs a layout, which
                    // if we havent set the anchor info properly yet makes dock/anchor layout cranky.
                    if (value == DockStyle.None)
                    {
                        if (dockNeedsLayout)
                        {
                            // We are transitioning from docked to not docked, restore the original bounds.
                            element.SetBounds(CommonProperties.GetSpecifiedBounds(element), BoundsSpecified.None);
                            // Restore Anchor information as its now relevant again.
                            UpdateAnchorInfo(element);
                        }
                    }
                    else
                    {
                        // Now setup the new bounds.
                        element.SetBounds(CommonProperties.GetSpecifiedBounds(element), BoundsSpecified.All);
                    }
                }
            }

            Debug.Assert(GetDock(element) == value, "Error setting Dock value.");
        }
예제 #2
0
 public static void SetDock(IArrangedElement element, DockStyle value)
 {
     if (GetDock(element) != value)
     {
         if (!System.Windows.Forms.ClientUtils.IsEnumValid(value, (int)value, 0, 5))
         {
             throw new InvalidEnumArgumentException("value", (int)value, typeof(DockStyle));
         }
         bool needsDockLayout = CommonProperties.GetNeedsDockLayout(element);
         CommonProperties.xSetDock(element, value);
         using (new LayoutTransaction(element.Container as Control, element, PropertyNames.Dock))
         {
             if (value == DockStyle.None)
             {
                 if (needsDockLayout)
                 {
                     element.SetBounds(CommonProperties.GetSpecifiedBounds(element), BoundsSpecified.None);
                     UpdateAnchorInfo(element);
                 }
             }
             else
             {
                 element.SetBounds(CommonProperties.GetSpecifiedBounds(element), BoundsSpecified.All);
             }
         }
     }
 }
예제 #3
0
        internal static void UpdateSpecifiedBounds(IArrangedElement element, int x, int y, int width, int height, BoundsSpecified specified)
        {
            Rectangle originalBounds = CommonProperties.GetSpecifiedBounds(element);

            // PERF note: Bitwise operator usage intentional to optimize out branching.

            bool xChangedButNotSpecified = ((specified & BoundsSpecified.X) == BoundsSpecified.None) & x != originalBounds.X;
            bool yChangedButNotSpecified = ((specified & BoundsSpecified.Y) == BoundsSpecified.None) & y != originalBounds.Y;
            bool wChangedButNotSpecified = ((specified & BoundsSpecified.Width) == BoundsSpecified.None) & width != originalBounds.Width;
            bool hChangedButNotSpecified = ((specified & BoundsSpecified.Height) == BoundsSpecified.None) & height != originalBounds.Height;

            if (xChangedButNotSpecified | yChangedButNotSpecified | wChangedButNotSpecified | hChangedButNotSpecified)
            {
                // if any of them are changed and specified cache the new value.

                if (!xChangedButNotSpecified)
                {
                    originalBounds.X = x;
                }

                if (!yChangedButNotSpecified)
                {
                    originalBounds.Y = y;
                }

                if (!wChangedButNotSpecified)
                {
                    originalBounds.Width = width;
                }

                if (!hChangedButNotSpecified)
                {
                    originalBounds.Height = height;
                }

                element.Properties.SetRectangle(_specifiedBoundsProperty, originalBounds);
            }
            else
            {
                // SetBoundsCore is going to call this a lot with the same bounds.  Avoid the set object
                // (which indirectly may causes an allocation) if we can.
                if (element.Properties.ContainsObject(_specifiedBoundsProperty))
                {
                    // use MaxRectangle instead of null so we can reuse the SizeWrapper in the property store.
                    element.Properties.SetRectangle(_specifiedBoundsProperty, LayoutUtils.s_maxRectangle);
                }
            }
        }