public void AlignVCenter() { int MinLeft = MAX; int MaxRight = 0; int VCenter = 0; int tempL; int tempR; int n = SelectionCount; for (int i = 0; i < n; i++) { DrawObject o = GetSelectedObject(i); if (o.ObjectType == Global.DrawType.DrawLine) { DrawLine l = (DrawLine)o; tempL = Math.Min(l.StartPoint.X, l.EndPoint.X); tempR = Math.Max(l.StartPoint.X, l.EndPoint.X); } else { tempL = o.ShapeRect.X; tempR = o.ShapeRect.Right; } if (tempL < MinLeft) { MinLeft = tempL; } if (tempR > MaxRight) { MaxRight = tempR; } } VCenter = (MinLeft + MaxRight) / 2; for (int i = 0; i < n; i++) { DrawObject o = GetSelectedObject(i); if (o.ObjectType == Global.DrawType.DrawLine) { DrawLine l = (DrawLine)o; l.Move(VCenter - (l.StartPoint.X + l.EndPoint.X) / 2, 0); } else { int center = (o.ShapeRect.Left + o.ShapeRect.Right) / 2; o.ShapeRect = new Rectangle(o.ShapeRect.Left + (VCenter - center), o.ShapeRect.Top, o.ShapeRect.Width, o.ShapeRect.Height); } } }