Exemple #1
3
        private void 열기ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog chooser = new OpenFileDialog();

            chooser.Title            = "File Open";
            chooser.Filter           = "All Files (*.*)|*.*";
            chooser.InitialDirectory = ".";
            if (chooser.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            _fileName = chooser.FileName;
            _figures.Clear();
            _selectedFigure = null;


            BinaryFormatter formatter = new BinaryFormatter();
            Stream          input     = File.OpenRead(_fileName);

            _figures = (FigureList)formatter.Deserialize(input);
            input.Close();


            for (int i = 0; i < _figures.Count; i++)
            {
                Figure ptr = _figures.getAt(i);
                ptr.makeRegion();
                ptr.setView(canvas);
                if (ptr is Point)
                {
                    ptr.setPopup(pointPopup);
                }
                else if (ptr is Line)
                {
                    ptr.setPopup(linePopup);
                }
                else if (ptr is Box)
                {
                    ptr.setPopup(boxPopup);
                }
                else if (ptr is Circle)
                {
                    ptr.setPopup(circlePopup);
                }
            }
            canvas.Invalidate();
        }
Exemple #2
0
 private void canvas_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         _selectedFigure = null;
         for (int i = 0; i < _figures.Count; i++)
         {
             Figure fig = _figures.getAt(i);
             if (fig.ptInRegion(e.X, e.Y))
             {
                 _selectedFigure = fig;
                 break;
             }
         }
         if (_selectedFigure != null)
         {
             _selectedFigure.popup(canvas, e.Location);
         }
         else
         {
             mainPopup.popup(canvas, e.Location);
         }
     }
     else
     {
         _selectedFigure = null;
         for (int i = 0; i < _figures.Count; i++)
         {
             Figure fig = _figures.getAt(i);
             if (fig.ptInRegion(e.X, e.Y))
             {
                 _selectedFigure = fig;
                 break;
             }
         }
         if (_selectedFigure != null)
         {
             _figures.removeFigure(_selectedFigure);
             _currentX   = e.X;
             _currentY   = e.Y;
             _actionMode = MOVING;
             canvas.Invalidate();
             return;
         }
         Graphics g    = canvas.CreateGraphics();
         Pen      aPen = new Pen(Color.Black, 2);
         if (whatToDraw == DRAW_RECT)
         {
             _selectedFigure = new Box(canvas, e.X, e.Y, e.X, e.Y);
             _selectedFigure.setPopup(boxPopup);
         }
         else if (whatToDraw == DRAW_LINE)
         {
             _selectedFigure = new Line(canvas, e.X, e.Y, e.X, e.Y);
             _selectedFigure.setPopup(linePopup);
         }
         else if (whatToDraw == DRAW_CIRCLE)
         {
             _selectedFigure = new Circle(canvas, e.X, e.Y, e.X, e.Y);
             _selectedFigure.setPopup(circlePopup);
         }
         else if (whatToDraw == DRAW_POINT)
         {
             _selectedFigure = new Point(canvas, e.X, e.Y);
             _selectedFigure.setPopup(pointPopup);
         }
         _selectedFigure.draw(g);
         bMousePressed = true;
         _actionMode   = DRAWING;
     }
 }