Compartir a través de


Introduction to the Line and Shape Controls (Visual Studio)

The Visual Basic Power Packs Line and Shape controls are a set of three graphical controls that enable you to draw lines and shapes on forms and containers. The LineShape control is used to draw horizontal, vertical, and diagonal lines. The OvalShape control is used to draw circles and ovals, and the RectangleShape control is used to draw rectangles and squares.

Line and Shape Controls

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:

  • Graphics methods can be called only at run time. Line and Shape controls can be added to a form at design time. This enables you to see what they look like and to position them exactly; they can also be added at run time.

  • Line and Shape controls are selectable at run time, providing events such as Click and OnDoubleClick. The outputs of graphics methods are not selectable and do not provide events.

  • Line and Shape controls provide BringToFront and SendToBack methods that enable you to control their z-order at design time and at run time. The z-order of graphics methods can be controlled only by changing their order of execution at run time.

  • Line and Shape controls are windowless controls; they have no window handles and therefore use less system resources.

Object Model

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

A diagram of the 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.

Note

Not all container controls support the Line and Shape controls. You cannot host a Line or Shape control on a TableLayoutPanel or a FlowLayoutPanel.

See Also

Tasks

How to: Draw Lines with the LineShape Control (Visual Studio)

How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)

How to: Enable Tabbing Between Shapes (Visual Studio)

Reference

Microsoft.VisualBasic.PowerPacks