tags:

views:

73

answers:

1

Hello, I have been trying to create a generic list of graphic objects. the code works fine for the first object but all subsequent objects are not working properly. I have included an image to show the desired effect.

any help would be appreciated

public partial class Form1 : Form
{
    private GraphicList graphicCollection = new GraphicList();

    public Form1()
    {
        graphicCollection.Add(new GraphicObj("obj_1", 200, 10, 125, 125));
        graphicCollection.Add(new GraphicObj("obj_2", 10, 10, 125, 125));

        this.Paint += new PaintEventHandler(Form1_Paint);
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        graphicCollection.draw(e.Graphics);
    }
}

list object

public class GraphicList : List<GraphicObj>
{
    public void draw(Graphics g)
    {
      for (int i = 0; i < this.Count; i++)
        this[i].Draw(g);
    }

}

Graphics Object class

public class GraphicObj
{
    public string Name { get; set; }
    public Point Location { get; set; }
    public int width { get; set; }
    public int height { get; set; }

    private int state = 2;

    public GraphicObj(string name, int x, int y, int _width, int _height)
    {
        Name = name;
        Location = new Point(x, y);
        width = _width;
        height = _height;
    }


    public void Draw(Graphics gfx)
    {
        Rectangle r = new Rectangle(Location.X, Location.Y, width, height);

        GraphicsPath pTemp = new GraphicsPath();

        pTemp.AddEllipse(r);
        Color[] colors = new Color[3];

        colors[0] = Color.Green;
        colors[1] = Color.LightGreen;
        colors[2] = Color.FromArgb(230, 250, 230);


        float[] positions = new float[3];
        positions[0] = 0f;
        positions[1] = 0.81f;
        positions[2] = 1f;

        ColorBlend Cb = new ColorBlend();
        Cb.Colors = colors;
        Cb.Positions = positions;

        PathGradientBrush pgb = new PathGradientBrush(pTemp);
        pgb.InterpolationColors = Cb;
     // old line   pgb.CenterPoint = new PointF(this.width*.75f, this.width*.35f);
        pgb.CenterPoint = new PointF(Location.X+ (width * .75f),Location.Y+ (width * .35f)); 
        gfx.FillPath(pgb, pTemp);

        if(pTemp != null)
            pTemp.Dispose();

        if(pgb != null)
            pgb.Dispose();
    }
}

alt text

A: 

found it...sorry to bother anyone

very foolish mistake!!

fishhead