![](http://imgdetail.ebookreading.net/software_development/33/9780470596906/9780470596906__stephens-c-programming__9780470596906__bg14a.png)
308
LESSON 25 Fine-Tuning Classes
public override void Draw(Graphics gr)
{
Draw(gr, Pens.Black, Brushes.Transparent);
}
Repeat the previous steps for the
ShapeEllipse class.
1. The following code shows the ShapeEllipse class’s code:
class ShapeEllipse : Shape
{
public ShapeEllipse(int x, int y, int width, int height)
: base(x, y, width, height)
{
}
public override void Draw(Graphics gr, Pen pen, Brush brush)
{
gr.FillEllipse(brush, Bounds);
gr.DrawEllipse(pen, Bounds);
}
public override void Draw(Graphics gr)
{
Draw(gr, Pens.Black, Brushes.Transparent);
}
}
In the main form, create a
List<Shape>.
1. Use code similar to the following:
// Our list of shapes to draw.
List<Shape> Shapes = new List<Shape>();
In the form’s
Load event handler, create some ShapeRectangles and ShapeEllipses and
add them to the list.
1. You can use code similar to the following, or you can create any ShapeEllipse and
ShapeRectangle objects that you like:
// Make some shapes.
private void Form1_Load(object sender, EventArgs e)
{
Shapes.Add(new ShapeEllipse(50, 50, 200, 200));
Shapes.Add(new ShapeEllipse(100, 80, 40, 60));
Shapes.Add(new ShapeEllipse(100, 80, 40, 60));
Shapes.Add(new ShapeEllipse(120, 100, 20, 30));
Shapes.Add(new ShapeEllipse(160, 80, 40, 60));
Shapes.Add(new ShapeEllipse(180, 100, 20, 30));
Shapes.Add(new ShapeEllipse(135, 130, 30, 50));
Shapes.Add(new ShapeRectangle(120, 190, 60, 5));
Shapes.Add(new ShapeRectangle(75, 25, 150, 50));
Shapes.Add(new ShapeRectangle(50, 75, 200, 10));
}
596906c25.indd 308 4/7/10 12:33:59 PM