コード例 #1
0
        /// <summary>
        /// Прихващане на координатите при натискането на бутон на мишката и проверка (в обратен ред) дали не е
        /// щракнато върху елемент. Ако е така то той се отбелязва като селектиран и започва процес на "влачене".
        /// Промяна на статуса и инвалидиране на контрола, в който визуализираме.
        /// Реализацията се диалогът с потребителя, при който се избира "най-горния" елемент от екрана.
        /// </summary>
        void ViewPortMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (dialogProcessor.CurrentTool == ToolSet.Selection)
            {
                Shape selectedShape = dialogProcessor.ContainsPoint(e.Location);

                if (selectedShape == null)
                {
                    return;
                }

                if (dialogProcessor.Selection.Contains(selectedShape))
                {
                    dialogProcessor.Selection.Remove(selectedShape);
                }
                else
                {
                    dialogProcessor.Selection.Add(selectedShape);
                }
                statusBar.Items[0].Text      = "Последно действие: Селекция на примитив";
                dialogProcessor.IsDragging   = true;
                dialogProcessor.LastLocation = e.Location;
                viewPort.Invalidate();
                //ReloadShapesList();
            }
            else if (dialogProcessor.CurrentTool == ToolSet.DrawEllipse)
            {
                dialogProcessor.AddEllipse(false, e.X, e.Y);
                viewPort.Invalidate();
                //ReloadShapesList();
            }
            else if (dialogProcessor.CurrentTool == ToolSet.DrawRectangle)
            {
                dialogProcessor.AddRectangle(false, e.X, e.Y);
                viewPort.Invalidate();
            }
            else if (dialogProcessor.CurrentTool == ToolSet.DrawCircle)
            {
                dialogProcessor.AddCircle(false, e.X, e.Y);
                viewPort.Invalidate();
                //ReloadShapesList();
            }
            else if (dialogProcessor.CurrentTool == ToolSet.DrawSquare)
            {
                dialogProcessor.AddSquare(false, e.X, e.Y);
                viewPort.Invalidate();
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Svetloslav1/PaintProgram
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            dialogProcessor.AddCircle();

            statusBar.Items[0].Text = "Последно действие: Рисуване на кръг";

            viewPort.Invalidate();
        }
コード例 #3
0
        PointF pt1;// = new PointF();
        void ViewPortMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (drawRectangleSpeedButton.Checked)
            {
                if (drawing == false)
                {
                    dialogProcessor.pressedAt  = e.Location;
                    dialogProcessor.currentPos = e.Location;
                    dialogProcessor.AddRectangle();
                    if (dialogProcessor.Selection != null)
                    {
                        setProperties(dialogProcessor.Selection);
                    }
                    drawing = true;
                }
                else
                {
                    dialogProcessor.Selection.Translate(e.Location);
                    setProperties(dialogProcessor.Selection);
                    drawing = false;
                }
            }
            else if (lineBtn.Checked)
            {
                if (drawing == false)
                {
                    dialogProcessor.pressedAt  = e.Location;
                    dialogProcessor.currentPos = e.Location;
                    pt1 = new PointF();
                    pt1 = e.Location;
                    if (pt1 != null)
                    {
                        dialogProcessor.AddLine(pt1, e.Location);
                    }
                    if (dialogProcessor.Selection != null)
                    {
                        setProperties(dialogProcessor.Selection);
                    }
                    drawing = true;
                }
                else
                {
                    dialogProcessor.Selection.Translate(e.Location);
                    setProperties(dialogProcessor.Selection);
                    drawing = false;
                }
            }
            else if (ellipseBtn.Checked)
            {
                if (drawing == false)
                {
                    dialogProcessor.pressedAt  = e.Location;
                    dialogProcessor.currentPos = e.Location;
                    pt1 = new PointF();
                    pt1 = e.Location;
                    if (pt1 != null)
                    {
                        dialogProcessor.AddCircle(pt1, e.Location);
                    }
                    if (dialogProcessor.Selection != null)
                    {
                        setProperties(dialogProcessor.Selection);
                    }
                    drawing = true;
                }
                else
                {
                    dialogProcessor.Selection.Translate(e.Location);
                    setProperties(dialogProcessor.Selection);
                    drawing = false;
                }
            }

            if (dialogProcessor.Selection == null)
            {
                nameTxt.Text       = "";
                colorBtn.BackColor = SystemColors.Control;
                opacityTxt.Text    = "";
                xtxt.Text          = "";
                ytxt.Text          = "";
                typeTxt.Text       = "";
                widthTxt.Text      = "";
                heightTxt.Text     = "";
                foreach (Shape shape in dialogProcessor.ShapeList)
                {
                    shape.Selected = false;
                }
            }

            dialogProcessor.releasedAt     = e.Location;
            dialogProcessor.IsDragging     = false;
            dialogProcessor.isTransforming = false;
            viewPort.Invalidate();
        }