How to: Draw Lines with the LineShape Control (Visual Studio)
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
Drag the LineShape control from the Visual Basic PowerPacks tab in the Toolbox drag to a form or container control.
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.
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
On the Project menu, click Add Reference.
In the Add Reference dialog box, select Microsoft.VisualBasic.PowerPacks.VS, and then click OK.
In the Code Editor, add an Imports or using statement at the top of the module:
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)
ShapeContainer canvas = new ShapeContainer(); LineShape theLine = new LineShape(); // Set the form as the parent of the ShapeContainer. canvas.Parent = this; // 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);