How to: Draw Lines with the LineShape Control (Visual Studio)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
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 Customizing Development Settings in Visual Studio.
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
Y2properties in the Properties window.
In the Properties window, optionally set additional properties such as
BorderColorto change the appearance of the line.
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
usingstatement at the top of the module:
Add the following code in an
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);