Exemple #1
0
        private void panel2_MouseUp(object sender, MouseEventArgs e)
        {
            switch (drawingMode)
            {
            case DrawMode.Square:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new Pen(Pen, 2), drawingMode));
                break;

            case DrawMode.Circle:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new Pen(Pen, 2), drawingMode));
                break;

            case DrawMode.FillSquare:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new SolidBrush(Fill), drawingMode));
                break;

            case DrawMode.FillCircle:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new SolidBrush(Fill), drawingMode));
                break;

            case DrawMode.Line:
                shapeList.Add(new Shape(dimensions.Anchor, dimensions.end, new Pen(Pen, 2), drawingMode));
                break;
            }

            PaintCanvas.Invalidate();

            anchor = Point.Empty;
            dimensions.Update(anchor, Point.Empty);
            dimensions.UpdateLine(anchor, Point.Empty);
            isDrawingMode = false; //upon mouse release, user cannot draw unless he clicks on canvas again
        }
Exemple #2
0
 private void undoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int n = shapeList.Count - 1;
         History.Add(shapeList[n]);
         shapeList.RemoveAt(n);
         PaintCanvas.Invalidate();
     }
     catch (Exception) { }
 }
Exemple #3
0
 private void redoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int o = History.Count - 1;
         shapeList.Add(History[o]);
         History.RemoveAt(o);
         o--;
         PaintCanvas.Invalidate();
     }
     catch (Exception) { }
 }
Exemple #4
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e) //for newcanvas, we remove each shape from the list
        {
            List <Shape> valuesToDelete = new List <Shape>();

            foreach (Shape s in shapeList)
            {
                valuesToDelete.Add(s);
            }

            foreach (Shape s in valuesToDelete)
            {
                shapeList.Remove(s);
            }

            PaintCanvas.Invalidate();
        }
Exemple #5
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) //coding for saving the canvas size as bmp
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt = "bmp";
            saveFileDialog.Filter     = "Bitmap files|*.bmp";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                int width  = PaintCanvas.Width;
                int height = PaintCanvas.Height;

                Bitmap    bitMap = new Bitmap(width, height);
                Rectangle rec    = new Rectangle(0, 0, width, height);

                PaintCanvas.DrawToBitmap(bitMap, rec);
                bitMap.Save(saveFileDialog.FileName);
            }
        }
Exemple #6
0
 public void setHoveringObject(PaintObject hoveringObject)
 {
     this.hoveringObject = hoveringObject;
     if (hoveringObject != null)
     {
         hoveringRender.Visibility = Visibility.Visible;
         hoveringRender.Width      = hoveringRender.Height = hoveringObject.getThickness() + 2;
         double offset = hoveringObject.getThickness() / 2 + 1;
         hoveringRender.Fill = new SolidColorBrush(hoveringObject.getColor());
         PaintCanvas.SetLeft(hoveringRender, hoveringObject.getStartX() - offset);
         PaintCanvas.SetTop(hoveringRender, hoveringObject.getStartY() - offset);
         PaintCanvas.SetZIndex(hoveringRender, 10);
     }
     else
     {
         hoveringRender.Visibility = Visibility.Hidden;
     }
 }
Exemple #7
0
        private void panel2_MouseMove(object sender, MouseEventArgs e)
        {
            // update our delta location
            delta.X = e.X;
            delta.Y = e.Y;

            newPointerX.X = e.X;
            newPointerX.Y = e.Y;
            toolStripStatusLabel1.Text = Math.Abs(delta.X).ToString() + "," + "" + Math.Abs(delta.Y).ToString() + " px";

            if (isDrawingMode)
            {
                Point currentPt = new Point(delta.X - anchor.X, delta.Y - anchor.Y);
                toolStripStatusLabel2.Text = Math.Abs(currentPt.X).ToString() + "," + "" + Math.Abs(currentPt.Y).ToString() + " px";

                if (drawingMode == DrawMode.Brush)
                {
                    int  r = (int)Convert.ToInt32(BrushWidthComboBox.SelectedItem.ToString());
                    Size a = new Size(r, r);
                    shapeList.Add(new Shape(delta, new SolidBrush(BrushColorBox.BackColor), a, drawingMode));
                }

                if (drawingMode == DrawMode.Pen)
                {
                    shapeList.Add(new Shape(oldPointerX, newPointerX, new Pen(PenColorBox.BackColor, 1), drawingMode));
                    oldPointerX = newPointerX;
                }

                if (drawingMode == DrawMode.Erase)
                {
                    Size a = new Size(25, 25);
                    shapeList.Add(new Shape(delta, new SolidBrush(PaintCanvas.BackColor), a, drawingMode));
                }

                if (drawingMode == DrawMode.Line)
                {
                    dimensions.UpdateLine(anchor, delta);
                }

                dimensions.Update(anchor, delta);
            }
            // redraw the form
            PaintCanvas.Invalidate();
        }
Exemple #8
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e) //code for opening BMP file
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.DefaultExt = "bmp";
            openFileDialog.Filter     = "Bitmap files|*.bmp";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                imagePath = openFileDialog.FileName;
                Image imgBitmap = new Bitmap(imagePath);

                drawingMode = DrawMode.Image;
                shapeList.Add(new Shape(imgBitmap, drawingMode));
                this.PaintCanvas.Size = imgBitmap.Size;
            }

            drawingMode = DrawMode.Square;
            PaintCanvas.Invalidate();
        }