Tuesday, January 10, 2006

Draw a line at design time in Visual Studio

In Visual Basic 6.0 there was a Line control that could be used to draw a line on a form. In VBA, VB.NET, Visual Basic 2005 and other similar programs there is no line control that you can use. The most lightweight and easy thing to do is to use a Label control. Set Height or Width to 1 depending on if you want the line horizontal or vertical Clear the Caption / Text Set the BorderStyle to None Set AutoSize to False Set the BackColor to the color of the line If you want a thicker line increase the height or width Now if you want to draw a diagonal line you have to code a little
' Visual Basic 2005
Private Sub FormPaint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    ' Draw a diagonal line from the top left to the lower right.
    e.Graphics.DrawLine(Pens.Black, 0, 0, Me.ClientSize.Width, _
End Sub

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner