/// <summary> /// 移动图元 /// </summary> /// <param name="p">移动的相对位置</param> public override void Move(Size s) { if (selected) // 缩放控制点在被选中状态,改变它对应的插槽容器的大小 { int newX; int newY; Size locationDistancement = new Size(0, 0); Size elementSizeDistancement = new Size(0, 0); bool resizeSlotContainer = false; // 是否缩放插槽容器 switch (direction) { case Direction.Up: { locationDistancement = new Size(0, s.Height); elementSizeDistancement = new Size(0, -s.Height); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X; newY = location.Y + s.Height; location = new Point(newX, newY); textRectangle.Location += new Size(0, s.Height); activateRectangle.Location += new Size(0, s.Height); resizeSlotContainer = true; } break; } case Direction.Up_Left: { locationDistancement = new Size(s.Width, s.Height); elementSizeDistancement = new Size(-s.Width, -s.Height); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X + s.Width; newY = location.Y + s.Height; location = new Point(newX, newY); textRectangle.Location += new Size(s.Width, s.Height); activateRectangle.Location += new Size(s.Width, s.Height); resizeSlotContainer = true; } break; } case Direction.Left: { locationDistancement = new Size(s.Width, 0); elementSizeDistancement = new Size(-s.Width, 0); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X + s.Width; newY = location.Y; location = new Point(newX, newY); textRectangle.Location += new Size(s.Width, 0); activateRectangle.Location += new Size(s.Width, 0); resizeSlotContainer = true; } break; } case Direction.Down_Left: { locationDistancement = new Size(s.Width, 0); elementSizeDistancement = new Size(-s.Width, s.Height); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X + s.Width; newY = location.Y + s.Height; location = new Point(newX, newY); textRectangle.Location += new Size(s.Width, s.Height); activateRectangle.Location += new Size(s.Width, s.Height); resizeSlotContainer = true; } break; } case Direction.Down: { elementSizeDistancement = new Size(0, s.Height); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X; newY = location.Y + s.Height; location = new Point(newX, newY); textRectangle.Location += new Size(0, s.Height); activateRectangle.Location += new Size(0, s.Height); resizeSlotContainer = true; } break; } case Direction.Down_Right: { elementSizeDistancement = new Size(s.Width, s.Height); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X + s.Width; newY = location.Y + s.Height; location = new Point(newX, newY); textRectangle.Location += new Size(s.Width, s.Height); activateRectangle.Location += new Size(s.Width, s.Height); resizeSlotContainer = true; } break; } case Direction.Right: { elementSizeDistancement = new Size(s.Width, 0); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X + s.Width; newY = location.Y; location = new Point(newX, newY); textRectangle.Location += new Size(s.Width, 0); activateRectangle.Location += new Size(s.Width, 0); resizeSlotContainer = true; } break; } case Direction.Up_Right: { locationDistancement = new Size(0, s.Height); elementSizeDistancement = new Size(s.Width, -s.Height); // 保证调整后图元的大小大于其最小大小 if ((slotContainer.ElementSize.Width + elementSizeDistancement.Width >= slotContainer.MinSize.Width) && (slotContainer.ElementSize.Height + elementSizeDistancement.Height >= slotContainer.MinSize.Height)) { newX = location.X + s.Width; newY = location.Y + s.Height; location = new Point(newX, newY); textRectangle.Location += new Size(s.Width, s.Height); activateRectangle.Location += new Size(s.Width, s.Height); resizeSlotContainer = true; } break; } } // 调整缩放控制点对应的插槽容器的大小 if (resizeSlotContainer) { slotContainer.MoveBorder(locationDistancement, elementSizeDistancement); } } else // 在非选中状态下,则直接移动缩放控制点即可 { this.location += s; textRectangle.Location += s; activateRectangle.Location += s; } }