Пример #1
0
 private void PnlPaint_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         haveClicked = true;
         if (chooseShape == 1)
         {
             myShape            = new clsLine();
             myShape.shapeStyle = 1;
             myShape.p1         = e.Location;
             myShape.pen        = setPen();
             shapes.Add(myShape);
         }
         else if (chooseShape == 2)
         {
             myShape    = new clsEllipse();
             myShape.p1 = e.Location;
             if (shapeStyle == 1)
             {
                 myShape.pen        = setPen();
                 myShape.shapeStyle = 1;
             }
             else
             {
                 if (cbbBrushStyle.SelectedItem.ToString() == "Solid")
                 {
                     myShape.solidBrush    = new SolidBrush(btnFillColor.BackColor);
                     myShape.useSolidBrush = true;
                 }
                 else
                 {
                     myShape.hatchBrush    = setHatchBrush();
                     myShape.useSolidBrush = false;
                 }
                 if (shapeStyle == 2)
                 {
                     myShape.shapeStyle = 2;
                 }
                 else
                 {
                     myShape.pen        = setPen();
                     myShape.shapeStyle = 3;
                 }
             }
             shapes.Add(myShape);
         }
         else if (chooseShape == 3)
         {
             myShape    = new clsRectangle();
             myShape.p1 = e.Location;
             if (shapeStyle == 1)
             {
                 myShape.pen        = setPen();
                 myShape.shapeStyle = 1;
             }
             else
             {
                 if (cbbBrushStyle.SelectedItem.ToString() == "Solid")
                 {
                     myShape.solidBrush    = new SolidBrush(btnFillColor.BackColor);
                     myShape.useSolidBrush = true;
                 }
                 else
                 {
                     myShape.hatchBrush    = setHatchBrush();
                     myShape.useSolidBrush = false;
                 }
                 if (shapeStyle == 2)
                 {
                     myShape.shapeStyle = 2;
                 }
                 else
                 {
                     myShape.pen        = setPen();
                     myShape.shapeStyle = 3;
                 }
             }
             shapes.Add(myShape);
         }
         else if (chooseShape == 4)
         {
             if (newCurveOrPolygon)
             {
                 myShape = new clsCurve();
                 myShape.points.Add(e.Location);
                 myShape.points.Add(e.Location);
                 myShape.shapeStyle = 1;
                 myShape.pen        = setPen();
                 shapes.Add(myShape);
                 newCurveOrPolygon = false;
             }
             else
             {
                 myShape.points.Add(e.Location);
                 myShape.points.Add(e.Location);
             }
         }
         else if (chooseShape == 5)
         {
             if (newCurveOrPolygon)
             {
                 myShape = new clsPolygon();
                 myShape.points.Add(e.Location);
                 myShape.points.Add(e.Location);
                 if (shapeStyle == 1)
                 {
                     myShape.pen        = setPen();
                     myShape.shapeStyle = 1;
                 }
                 else
                 {
                     if (cbbBrushStyle.SelectedItem.ToString() == "Solid")
                     {
                         myShape.solidBrush    = new SolidBrush(btnFillColor.BackColor);
                         myShape.useSolidBrush = true;
                     }
                     else
                     {
                         myShape.hatchBrush    = setHatchBrush();
                         myShape.useSolidBrush = false;
                     }
                     if (shapeStyle == 2)
                     {
                         myShape.shapeStyle = 2;
                     }
                     else
                     {
                         myShape.pen        = setPen();
                         myShape.shapeStyle = 3;
                     }
                 }
                 shapes.Add(myShape);
                 newCurveOrPolygon = false;
             }
             else
             {
                 myShape.points.Add(e.Location);
                 myShape.points.Add(e.Location);
             }
         }
         else if (chooseShape == 6)
         {
             oldLocation = e.Location;
             isSelecting = true;
             int i = indexOfShapeSelected(e.Location);
             if (i < 0)
             {
                 if (pnlPaint.Cursor != Cursors.Default)
                 {
                     return;
                 }
                 if (!selectManyShapes)
                 {
                     deselectAll();
                 }
             }
             else
             {
                 if (selectManyShapes)
                 {
                     shapes[i].isSelected = !shapes[i].isSelected;
                 }
                 else
                 {
                     deselectAll();
                     shapes[i].isSelected = true;
                     if (!(shapes[i] is clsGroup))
                     {
                         showPropertiesOfShape(shapes[i]);
                     }
                 }
                 redraw();
             }
         }
     }
     else
     {
         if (chooseShape == 4 || chooseShape == 5)
         {
             newCurveOrPolygon = true;
             haveClicked       = false;
             shapes[shapes.Count - 1].updatePoint();
         }
     }
 }
Пример #2
0
        private void showPropertiesOfShape(clsShape shape)
        {
            if (shape.shapeStyle == 1)
            {
                btnLineColor.BackColor = shape.pen.Color;
                trbWidth.Value         = (int)shape.pen.Width;
                lblWidth.Text          = trbWidth.Value.ToString();
                if (shape.pen.DashStyle == DashStyle.Dash)
                {
                    cbbDashStyle.Text = "Dash";
                }
                else if (shape.pen.DashStyle == DashStyle.DashDot)
                {
                    cbbDashStyle.Text = "DashDot";
                }
                else if (shape.pen.DashStyle == DashStyle.DashDotDot)
                {
                    cbbDashStyle.Text = "DashDotDot";
                }
                else if (shape.pen.DashStyle == DashStyle.Dot)
                {
                    cbbDashStyle.Text = "Dot";
                }
                else
                {
                    cbbDashStyle.Text = "Solid";
                }
            }
            else if (shape.shapeStyle == 2)
            {
                if (shape.useSolidBrush)
                {
                    btnFillColor.BackColor = shape.solidBrush.Color;
                    cbbBrushStyle.Text     = "Solid";
                }
                else
                {
                    btnFillColor.BackColor = shape.hatchBrush.ForegroundColor;
                    if (shape.hatchBrush.HatchStyle == HatchStyle.BackwardDiagonal)
                    {
                        cbbBrushStyle.Text = "BackwardDiagonal";
                    }
                    else if (shape.hatchBrush.HatchStyle == HatchStyle.DarkDownwardDiagonal)
                    {
                        cbbBrushStyle.Text = "DarkDownwardDiagonal";
                    }
                    else if (shape.hatchBrush.HatchStyle == HatchStyle.LightUpwardDiagonal)
                    {
                        cbbBrushStyle.Text = "LightUpwardDiagonal";
                    }
                    else if (shape.hatchBrush.HatchStyle == HatchStyle.Percent50)
                    {
                        cbbBrushStyle.Text = "Percent50";
                    }
                    else
                    {
                        cbbBrushStyle.Text = "Shingle";
                    }
                }
            }
            else
            {
                btnLineColor.BackColor = shape.pen.Color;
                trbWidth.Value         = (int)shape.pen.Width;
                lblWidth.Text          = trbWidth.Value.ToString();
                if (shape.pen.DashStyle == DashStyle.Dash)
                {
                    cbbDashStyle.Text = "Dash";
                }
                else if (shape.pen.DashStyle == DashStyle.DashDot)
                {
                    cbbDashStyle.Text = "DashDot";
                }
                else if (shape.pen.DashStyle == DashStyle.DashDotDot)
                {
                    cbbDashStyle.Text = "DashDotDot";
                }
                else if (shape.pen.DashStyle == DashStyle.Dot)
                {
                    cbbDashStyle.Text = "Dot";
                }
                else
                {
                    cbbDashStyle.Text = "Solid";
                }

                if (shape.useSolidBrush)
                {
                    btnFillColor.BackColor = shape.solidBrush.Color;
                    cbbBrushStyle.Text     = "Solid";
                }
                else
                {
                    btnFillColor.BackColor = shape.hatchBrush.ForegroundColor;
                    if (shape.hatchBrush.HatchStyle == HatchStyle.BackwardDiagonal)
                    {
                        cbbBrushStyle.Text = "BackwardDiagonal";
                    }
                    else if (shape.hatchBrush.HatchStyle == HatchStyle.DarkDownwardDiagonal)
                    {
                        cbbBrushStyle.Text = "DarkDownwardDiagonal";
                    }
                    else if (shape.hatchBrush.HatchStyle == HatchStyle.LightUpwardDiagonal)
                    {
                        cbbBrushStyle.Text = "LightUpwardDiagonal";
                    }
                    else if (shape.hatchBrush.HatchStyle == HatchStyle.Percent50)
                    {
                        cbbBrushStyle.Text = "Percent50";
                    }
                    else
                    {
                        cbbBrushStyle.Text = "Shingle";
                    }
                }
            }
        }