Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to save the triangle I drew and draw again while the previous triangle is still there. I did this in rectangle, square, circle and ellipse and it worked. I don't know why it won't in Triangle. IS there something wrong in the code?

What I have tried:

<pre>>This is how I draw and "save (not working)"

**Shape Class**    


        public void DrawTriangle(Color c, int stroke,PointF[] tpoints, float w, Graphics g)
        {
            this.width = w;
            this.strokeThickness = stroke;
            this.tPoints = tpoints;
            g.InterpolationMode = InterpolationMode.High;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.DrawPolygon(new Pen(c, stroke), tpoints);
        }
**Form 1**  

        public void DrawTriangle()
        {
            tC = Color.Red;
            strokeTriangle = trackBar_Stroke.Value;
            tW = Convert.ToInt32((Convert.ToInt32(tbox_Width.Text) * 96) / 25.4);
            tH = (Convert.ToInt32((tW * (Math.Sqrt(3))) / 2));
            tX = (pictureBox_Canvass.Width - tW) / 2;
            tY = ((pictureBox_Canvass.Width - (tH)) / 2) + tH;

            float angle = 0;
            t_Points[0].X = tX;
            t_Points[0].Y = tY;
            t_Points[1].X = (float)(tX + tW * Math.Cos(angle));
            t_Points[1].Y = (float)(tY + tW * Math.Sin(angle));
            t_Points[2].X = (float)(tX + tW * Math.Cos(angle - Math.PI / 3));
            t_Points[2].Y = (float)(tY + tW * Math.Sin(angle - Math.PI / 3));
        }
        public void AcceptTriangle()
        {
            Shape shape = new Shape();
            tC = Color.Gray;
            shape.strokeThickness = strokeTriangle;
            shape.width = tW;
            shape.x = tX;
            shape.y = tY;
            shape.tPoints = t_Points;
            s._triangle.Add(shape);
        }

>This is how I iterate it.


    public List<Shape> _triangle = new List<Shape>();
    foreach(Shape shapes3 in s._triangle)
            {
                shapes3.DrawTriangle(shapes3.color, shapes3.strokeThickness, shapes3.tPoints, shapes3.width, e.Graphics);
            }
Posted
Comments
[no name] 15-Sep-18 17:01pm    
Why aren't you using WPF "Shape" controls?

You're using "assembler" compared to all the options available.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900