예제 #1
0
        /// <summary>
        /// Space out a set of controls down the X axis
        /// </summary>
        /// <param name="pixelsBetween">Amount of pixels between each control</param>
        /// <param name="scaleForDisplay">If true, spacing is scaled to match display scaling factor</param>
        /// <param name="controls">The controls to distribute</param>
        public static void DistributeHorizontally(int pixelsBetween, bool scaleForDisplay, params object[] controls)
        {
            if (controls.Length < 2)
            {
                return;
            }

            /*
             *          Control parent = controls[0].Parent;
             #if DEBUG
             *          for (int i = 1; i < controls.Length; i++)
             *              if (parent != controls[i].Parent)
             *                  Debug.Fail("LayoutHelper.DistributeHorizontally() called on controls with different parents");
             #endif
             */

            if (scaleForDisplay)
            {
                pixelsBetween = Ceil(DisplayHelper.ScaleX(pixelsBetween));
            }
            Array.Sort(controls, new SortByHorizontalPosition());
            int pos = ControlAdapter.Create(controls[0]).Right + pixelsBetween;

            for (int i = 1; i < controls.Length; i++)
            {
                ControlAdapter ca = ControlAdapter.Create(controls[i]);
                if (ca.Visible)
                {
                    ca.Left = pos;
                    pos     = ca.Right + pixelsBetween;
                }
            }
        }
예제 #2
0
        public static void DistributeVertically(int pixelsBetween, bool sortByVerticalPosition, params object[] controls)
        {
            if (controls.Length < 2)
            {
                return;
            }

/*
 *                      Control parent = controls[0].Parent;
 #if DEBUG
 *                      for (int i = 1; i < controls.Length; i++)
 *                              if (parent != controls[i].Parent)
 *                                      Debug.Fail("LayoutHelper.DistributeVertically() called on controls with different parents");
 #endif
 */

            pixelsBetween = Ceil(DisplayHelper.ScaleY(pixelsBetween));
            if (sortByVerticalPosition)
            {
                Array.Sort(controls, new SortByVerticalPosition());
            }
            int pos = ControlAdapter.Create(controls[0]).Bottom + pixelsBetween;

            for (int i = 1; i < controls.Length; i++)
            {
                ControlAdapter ca = ControlAdapter.Create(controls[i]);
                if (ca.Visible || !sortByVerticalPosition)
                {
                    ca.Top = pos;
                    pos    = ca.Bottom + pixelsBetween;
                }
            }
        }
예제 #3
0
 public int Compare(object x, object y)
 {
     return(ControlAdapter.Create(x).Left - ControlAdapter.Create(y).Left);
 }