Exemplo n.º 1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (null == _shape)
            {
                return;
            }

            PointF mousePos = new PointF(e.X, e.Y);

            CustomComponents.Shape curShape = null;

            //if (Form1._isFill)
            //{
            //    curShape = FindShapeInCursor(mousePos);
            //    if (curShape != null)
            //    {
            //        curShape.ShapeBrush = Form1._brush.Clone() as SolidBrush;
            //        Invalidate();
            //    }
            //}

            curShape = FindControlPointInMousePoint(mousePos);

            if (null != curShape)
            {
                _isPressDown      = true;
                _shape            = curShape;
                _shape.IsSelected = true;
                Invalidate();
                _shape.MouseDown(e);
                return;
            }

            curShape = FindShapeInCursor(mousePos);

            if (null == curShape)
            {
                if (!_shape.IsDrawing)
                {
                    if (_shape.IsSelected)
                    {
                        _shape.IsSelected = false;
                        Invalidate();
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    _isPressDown = true;
                    _shape.MouseDown(e);
                    return;
                }
            }
            else
            {
                _isPressDown      = true;
                _shape            = curShape;
                _shape.IsSelected = true;
                _shape.ShapePen   = new Pen(Form1._drawingPen.Color, Form1._drawingPen.Width);
                _shape.MouseDown(e);
                Invalidate();
            }
        }
Exemplo n.º 2
0
        void Connect()
        {
            client_socket.Connect(IPAddress.Parse("127.0.0.1"), 9999);
            receiver           = new StreamReader(client_socket.GetStream());
            lbStatus.Text      = "Connected";
            lbStatus.ForeColor = Color.Green;
            int nShape = int.Parse(receiver.ReadLine());

            CustomComponents.Shape shape = null;

            for (int i = 0; i < nShape; ++i)
            {
                string type = receiver.ReadLine();

                if (type == "Rectangle")
                {
                    shape = new CustomComponents.RectangleShape();
                }
                else if (type == "Line")
                {
                    shape = new CustomComponents.Line();
                }
                else if (type == "Ellipse")
                {
                    shape = new CustomComponents.Ellipse();
                }
                else if (type == "Triangle")
                {
                    shape = new CustomComponents.Triangle();
                }
                else if (type == "Hexagon")
                {
                    shape = new CustomComponents.Hexagon();
                }
                else if (type == "Circle")
                {
                    shape = new CustomComponents.Circle();
                }

                shape.nControlPoint = int.Parse(receiver.ReadLine());
                string startPosX = receiver.ReadLine();
                string startPosY = receiver.ReadLine();
                string endPosX   = receiver.ReadLine();
                string endPosY   = receiver.ReadLine();

                if (type == "Circle")
                {
                    shape.StartPosition = new PointF(float.Parse(startPosX), float.Parse(startPosY));
                    shape.EndPosition   = new PointF(float.Parse(endPosX), float.Parse(endPosY));
                }
                else
                {
                    shape.StartPosition = new PointF(int.Parse(startPosX), int.Parse(startPosY));
                    shape.EndPosition   = new PointF(int.Parse(endPosX), int.Parse(endPosY));
                }

                shape.ShapePen.Width = int.Parse(receiver.ReadLine());
                shape.IsDrawing      = false;
                DoubleBufferedPanel._shapes.Add(shape);
            }

            pnSurface.Refresh();
        }