private void MoveSelection(ICustomPaint theElement, int xOrigin, int yOrigin) { if (theElement.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None) { theElement.X = xOrigin; } if (theElement.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None) { theElement.Y = yOrigin; } selectionRectangle = new TrackerRectangle(theElement.GetRegion(), theElement.HorizontalAlignment, theElement.VerticalAlignment); selectionRectangle.DrawSelectionTrackers((Bitmap)trackerImage); }
public void UpdateSelection(ICustomPaint theSelection, int action) { if (theSelection != null) { if (action == 0) { selectionRectangle = new TrackerRectangle(theSelection.GetRegion(), theSelection.HorizontalAlignment, theSelection.VerticalAlignment); trackerImage = (Bitmap)drawingImage.Clone(); selectionRectangle.DrawSelectionTrackers((Bitmap)trackerImage); PaintImage(trackerImage); selectedObjects.Clear(); selectedObjects.Add(theSelection); } else if (action == 1) { selectionRectangle = new TrackerRectangle(theSelection.GetRegion(), theSelection.HorizontalAlignment, theSelection.VerticalAlignment); selectionRectangle.DrawSelectionTrackers((Bitmap)trackerImage); PaintImage(trackerImage); selectedObjects.Add(theSelection); } else if (action == 2) { selectedObjects.Remove(theSelection); DoPaint(); } } else { selectedObjects.Clear(); selectionRectangle = null; trackerImage = (Bitmap)drawingImage.Clone(); PaintImage(drawingImage); } }
public void SelectObject(ICustomPaint theSelection) { if (theSelection != null) { selectedObject = theSelection; selectionRectangle = new TrackerRectangle(theSelection.GetRegion(), theSelection.HorizontalAlignment, theSelection.VerticalAlignment); trackerImage = (Bitmap)drawingImage.Clone(); selectionRectangle.DrawSelectionTrackers((Bitmap)trackerImage); PaintImage(trackerImage); } else { selectedObject = null; selectionRectangle = null; PaintImage(drawingImage); } }
private void PaintSelection(Graphics g) { if (selectionRectangle == null) { return; } trackerImage.Dispose(); trackerImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); foreach (ICustomPaint CurrentObject in this.selectedObjects) { ICustomPaint obj = (ICustomPaint)CurrentObject; selectionRectangle = new TrackerRectangle(obj.GetRegion(), obj.HorizontalAlignment, obj.VerticalAlignment); selectionRectangle.DrawSelectionTrackers((Bitmap)trackerImage); } PaintImage(trackerImage); }
public void DesignPane_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (mouseDown) { if (mMouseMode == MOUSE_MODE.SELECTED) { if (mBorder != RESIZE_BORDER.NONE) { int xOffset = 0; int yOffset = 0; CalculateStretchOffsets(e.X, e.Y, ref xOffset, ref yOffset, mBorder); trackerImage.Dispose(); trackerImage = (Bitmap)drawingImage.Clone(); for (int i = 0; i < selectedObjects.Count; i++) { ICustomPaint theObject = (ICustomPaint)selectedObjects[i]; switch (mBorder) { case RESIZE_BORDER.TOP: if (theObject.Height - yOffset >= 0) { if (theObject.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None) { theObject.Height -= yOffset; theObject.Y += yOffset; } else if (theObject.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Bottom || selectedObject.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Middle) { theObject.Y += yOffset; } } break; case RESIZE_BORDER.RIGHT: if (theObject.Width + xOffset >= 0) { theObject.Width += xOffset; } break; case RESIZE_BORDER.BOTTOM: if (theObject.Height + yOffset >= 0) { theObject.Height += yOffset; } break; case RESIZE_BORDER.LEFT: if (theObject.Width - xOffset >= 0) { if (theObject.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None) { theObject.Width -= xOffset; theObject.X += xOffset; } else if (theObject.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Right || theObject.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Center) { theObject.X += xOffset; } } break; } TrackerRectangle selRectangle = new TrackerRectangle(theObject.GetRegion(), theObject.HorizontalAlignment, theObject.VerticalAlignment); selRectangle.DrawSelectionTrackers((Bitmap)trackerImage); } PaintImage(trackerImage); shouldRepaint = true; } else { if (Math.Abs(e.X - ptStart.X) > 0 || Math.Abs(e.Y - ptStart.Y) > 0) { trackerImage.Dispose(); trackerImage = (Bitmap)drawingImage.Clone(); for (int i = 0; i < selectedObjects.Count; i++) { ICustomPaint theObject = (ICustomPaint)selectedObjects[i]; MoveSelection(theObject, theObject.X + e.X - ptStart.X, theObject.Y + e.Y - ptStart.Y); } PaintImage(trackerImage); ptStart = new Point(e.X, e.Y); shouldRepaint = true; } } if (OnMoving != null && selectedObjects.Count > 0) { OnMoving((ICustomPaint)selectedObjects[selectedObjects.Count - 1]); } } } else { if (selectedObjects.Count > 0) { for (int i = 0; i < selectedObjects.Count; i++) { ICustomPaint theObject = (ICustomPaint)selectedObjects[i]; Rectangle theArea = theObject.GetRegion(); theArea.Offset(-TrackerRectangle.m_nOffset, -TrackerRectangle.m_nOffset); theArea.Inflate(2 * TrackerRectangle.m_nOffset, 2 * TrackerRectangle.m_nOffset); if (theArea.Contains(e.X, e.Y)) { TrackerRectangle tmp = new TrackerRectangle(theObject.GetRegion(), theObject.HorizontalAlignment, theObject.VerticalAlignment); int nResult = 0; this.Cursor = tmp.CursorCheck(new Point(e.X, e.Y), ref nResult); this.mBorder = (RESIZE_BORDER)nResult; moveReferenceObject = (ICustomPaint)selectedObjects[i]; return; } } } this.Cursor = Cursors.Default; } }