This documentation is archived and is not being maintained.

How to: Draw Lines with the LineShape Control

Visual Studio 2005

You can use the LineShape control to draw horizontal, vertical, or diagonal lines on a form or container, both at design time and at run time.

Note   Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To draw a line at design time

  1. Drag the LineShape control from the Toolbox drag to a form or container control.

  2. Drag the sizing and move handles to size and position the line.

    You can also size and position the line by changing the X1, X2, Y1, and Y2 properties in the Properties window.

  3. In the Properties window, optionally set additional properties such as BorderStyle or BorderColor to change the appearance of the line.

To draw a line at run time

  1. On the Project menu, click Add Reference.

  2. In the Add Reference dialog box, select Microsoft.VisualBasic.PowerPacks, and then click OK.

  3. In the Code Editor, add an Imports statement at the top of the module:

    Imports Microsoft.VisualBasic.PowerPacks
    
  4. Add the following code in an Event procedure:

    Dim canvas As New ShapeContainer
    Dim theLine As New LineShape
    ' Set the form as the parent of the ShapeContainer.
    canvas.Parent = Me
    ' Set the ShapeContainer as the parent of the LineShape.
    theLine.Parent = canvas
    ' Set the starting and ending coordinates for the line.
    theLine.StartPoint = New System.Drawing.Point(0, 0)
    theLine.EndPoint = New System.Drawing.Point(640, 480)
    
    
Show: