Esempio n. 1
0
        private void pbMain_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Clicks != 1)
            {
                return;
            }
            switch (_drawMode)
            {
            case DrawMode.Undefined:
            case DrawMode.DragAndDrop:
            {
                if (_currentShapeFactory != null)
                {
                    _lastShape = _currentShapeFactory.GetShape(_currentPen, _currentBrush);
                    _lastShape.SetPostition(e.Location);
                    _drawMode = _lastShape.DrawMode();
                    _history.Add(_lastShape);
                    UpdateUndoRedo();
                    pbMain.Invalidate();
                }
                break;
            }

            case DrawMode.ByPoint:
            {
                if (_lastShape != null)
                {
                    _lastShape.AddPoint(e.Location);
                    _drawMode = _lastShape.DrawMode();
                    pbMain.Invalidate();
                }
                break;
            }
            }
        }
Esempio n. 2
0
 private void redoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     _history.Redo();
     UpdateUndoRedo();
     _lastShape = _history.LastItem;
     _drawMode  = DrawMode.Undefined;
     pbMain.Invalidate();
 }
Esempio n. 3
0
 private void ToolButtonClick(object sender, EventArgs e)
 {
     _drawMode            = DrawMode.Undefined;
     _currentShapeFactory = (BaseShapeFactory)((ToolStripButton)sender).Tag;
     foreach (var Tool in tsMain.Items)
     {
         if (Tool == sender)
         {
             continue;
         }
         if (Tool is ToolStripButton && ((ToolStripButton)Tool).Tag != null)
         {
             ((ToolStripButton)Tool).Checked = false;
         }
     }
 }
Esempio n. 4
0
        public FormMain()
        {
            InitializeComponent();

            _currentPen            = new Pen(Color.Black);
            _currentBrush          = new SolidBrush(Color.Empty);
            tsbLineColor.BackColor = Color.Black;
            tsbFillColor.BackColor = Color.Empty;
            _history  = new History();
            _drawMode = DrawMode.Undefined;
            saveToolStripMenuItem.Enabled = false;

            // Initialize buttons with factories
            tsbLine.Tag      = new LineFactory();
            tsbBroken.Tag    = new BrokenFactory();
            tsbRectangle.Tag = new RectangleFactory();
            tsbEllipse.Tag   = new EllipseFactory();
            tsbPolygon.Tag   = new PolygonFactory();
            _toolIndex       = 5;
        }
Esempio n. 5
0
 private void pbMain_DoubleClick(object sender, EventArgs e)
 {
     _drawMode = DrawMode.Undefined;
 }