Line and Shape controls encapsulate many of the graphics methods that are contained in the System.Drawing namespace. This enables you to draw lines and shapes in a single step without having to create graphics objects, pens, and brushes. Complex graphics techniques such as gradient fills can be accomplished by just setting some properties.
Although it is also possible to draw lines and shapes by using graphics methods, there are several advantages to using the Line and Shape controls:
Line and Shape controls derive from a base Shape class that defines their shared properties, methods, and events.
The following illustration shows the Line and Shape object hierarchy.
Line and Shape object hierarchy
The derived LineShape class contains properties, methods, and events that are unique to lines. The derived SimpleShape class is the base class for OvalShape and RectangleShape; it contains properties, methods, and events common to all shapes. You can also derive from SimpleShape to create your own Shape controls.
The OvalShape and RectangleShape classes can be used to draw circles, ovals, rectangles, and rectangles with rounded corners.
When a Line or Shape control is added to a form or container, an invisible ShapeContainer object is created. The ShapeContainer acts as a canvas for the shapes within each container control; each ShapeContainer has a corresponding ShapeCollection that enables you to iterate through the Line and Shape controls. You can move shapes from one container to another by using cut and paste or by dragging and dropping. When the last shape is removed from a container, the ShapeContainer is removed also.