Example #1
0
        private void picPreview_MouseUp(object sender, MouseEventArgs e)
        {
            if (_graphicsPath != null)
            {
                var customShape = new CustomShape();
                customShape.Path  = _graphicsPath;
                customShape.Pen   = _selectedShape == Shape.Highlighter ? _highlighterPen : _selectedPen;
                customShape.Shape = _selectedShape;
                _shapes.Add(customShape);
                _graphicsPath = null;
                picPreview.Invalidate();
            }

            if (null != _shape)
            {
                _shape = null;
            }
        }
Example #2
0
        private void picPreview_MouseDown(object sender, MouseEventArgs e)
        {
            if (_fileName.Length <= 0)
            {
                return;
            }

            _x = e.X;
            _y = e.Y;

            switch (_selectedShape)
            {
            case Shape.Unknown:
                break;

            case Shape.Pen:
            case Shape.Highlighter:
                _graphicsPath = new GraphicsPath();
                break;

            case Shape.Eraser:
                foreach (var path in _shapes)
                {
                    if (path.Path.GetBounds().Contains(e.Location))
                    {
                        _shapes.Remove(path);
                        picPreview.Invalidate();
                        break;
                    }
                }
                break;

            case Shape.Text:
                frmInsertText frmInsertTextDlg = new frmInsertText();
                if (frmInsertTextDlg.ShowDialog(this) == DialogResult.OK)
                {
                    CustomShape customShape = new CustomShape();
                    customShape.Shape = Shape.Text;
                    customShape.Pen   = new Pen(_selectedColor, 1);
                    GraphicsPath graphicsPath = new GraphicsPath();
                    graphicsPath.AddString(frmInsertTextDlg.SelectedText,
                                           frmInsertTextDlg.SelectedFont.FontFamily, (int)frmInsertTextDlg.SelectedFont.Style,
                                           frmInsertTextDlg.SelectedFont.Size, e.Location, StringFormat.GenericTypographic);
                    graphicsPath.FillMode = FillMode.Winding;
                    customShape.Path      = graphicsPath;
                    _shapes.Add(customShape);
                    picPreview.Invalidate();
                }
                break;

            case Shape.Selection:
                picPreview.Refresh();
                foreach (var shape in _shapes)
                {
                    if (shape.Path.GetBounds().Contains(e.Location))
                    {
                        var rectf    = shape.Path.GetBounds();
                        var rect     = new Rectangle((int)rectf.X, (int)rectf.Y, (int)rectf.Width, (int)rectf.Height);
                        var graphics = picPreview.CreateGraphics();
                        ControlPaint.DrawReversibleFrame(picPreview.RectangleToScreen(rect), Color.BurlyWood, FrameStyle.Dashed);
                        _shape = shape;
                        break;
                    }
                }
                break;

            default:
                break;
            }
        }