views:

171

answers:

2

in vb.net i would like to draw a regular line on a form. is there a control to do this?

+4  A: 

One way at design time is to use a Label control and set it's height, or width to 1 (2px and 3D border gives a nice chiseled effect). Or else you can manually draw using GDI:

Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawLine(myPen, 0, 0, 200, 200)
myPen.Dispose()
formGraphics.Dispose()
Mitch Wheat
I usually create a user control which does this.
Lucas Jones
+7  A: 

What Mitch Wheat said is generally regarded as the correct answer, and what I have done in the past. However, if you want to have a visual control that you can drag on to a form, add the Microsoft.VisualBasic.PowerPack to your visual studio toolbox. To do that right-click on toolbox select "Choose Items...". Locate "Line Shape" on the .Net Framework Components tab.

Mosquito Mike
+1. I didn't know about that.
Mitch Wheat
+1 This is handy.
Dusty