예제 #1
0
        private void pictureBox1_DragOver(object sender, DragEventArgs e)
        {
            int x = ((PictureBox)sender).PointToClient(new Point(e.X, e.Y)).X;
            int y = ((PictureBox)sender).PointToClient(new Point(e.X, e.Y)).Y;

            toolStripLabel1.Text = "X=" + x + ", Y=" + y;

            if (e.Data.GetData(typeof(Canvas.ShapeSelection)) != null)
            {
                Canvas.ShapeSelection shapeSelection = (Canvas.ShapeSelection)e.Data.GetData(typeof(Canvas.ShapeSelection));

                if (shapeSelection.grabArea == Canvas.GrabArea.AREA || shapeSelection.grabArea == Canvas.GrabArea.HANDLE_MIDCENTER)
                {
                    // Moving a shape
                    Cursor.Current    = Cursors.SizeAll;
                    pictureBox1.Image = canvas.DragShape(x, y, tempShape, mouseOffset);
                }
                else
                {
                    // Resizing a shape
                    Cursor.Current    = shapeSelection.cursor;
                    mouseOffset       = new Point(x - tempShape.x1, y - tempShape.y1);
                    tempShape         = canvas.ResizeShape(x, y, tempShape, shapeSelection.grabArea);
                    pictureBox1.Image = canvas.bitmap;
                }
            }
            else
            {
                // Dragging from toolbox
                pictureBox1.Image = canvas.DragShape(x, y, tempShape, mouseOffset);
            }
        }
예제 #2
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (currentTool == Tool.SELECT)
            {
                Canvas.ShapeSelection shapeSelection = canvas.ShapeAtPoint(e.Location);

                // User clicks empty area
                if (shapeSelection.index == -1)
                {
                    canvas.DeselectShapes();
                    canvas.Refresh();
                    pictureBox1.Image = canvas.bitmap;
                }

                foreach (ToolStripItem item in popUpMenu.Items)
                {
                    item.Enabled = (shapeSelection.index > -1 ? true : false);
                }

                if (e.Button == MouseButtons.Left)
                {
                    if (shapeSelection.index > -1)
                    {
                        // Pick up the shape, and initiate a drag / drop
                        canvas.SelectedShapeIndex = shapeSelection.index;
                        tempShape = canvas.SelectedShape.Clone();
                        canvas.Shapes.RemoveAt(shapeSelection.index);
                        canvas.Refresh();

                        tempShape.buffer  = canvas.GetBitmapRegion(tempShape.rect);
                        pictureBox1.Image = canvas.bitmap;

                        mouseOffset = new Point(e.X - tempShape.x1, e.Y - tempShape.y1);
                        pictureBox1.DoDragDrop(shapeSelection, DragDropEffects.Move);
                    }
                }
            }

            if (currentTool == Tool.LINE)
            {
                tempLine.x1 = e.X;
                tempLine.y1 = e.Y;
            }

            if (currentTool == Tool.TEXT)
            {
                tempTextBlock.x1 = e.X;
                tempTextBlock.y1 = e.Y;
            }
        }