Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar MSDN Visual Basic Community

Title Draw dashed lines with thickness greater than 1 dashed line, draw, dash Graphics

When you set DrawWidth, Visual Basic automatically resets drawing style to solid. You must draw thick dashed lines yourself. Subroutine DashLine calculates vectors in the direction of the line with the right length for the dashes and the skips between them. It then draws the dashes.

```Private Sub DashLine(ByVal obj As Object, ByVal x1 As _
Single, ByVal y1 As Single, ByVal x2 As Single, ByVal _
y2 As Single, ByVal dash_length As Single, ByVal _
skip_length As Single, ByVal draw_width As Integer)
Dim dash_dx As Single
Dim dash_dy As Single
Dim skip_dx As Single
Dim skip_dy As Single
Dim length As Single
Dim X As Single
Dim Y As Single
Dim i As Integer
Dim i_max As Integer

' Get vectors in the desired direction
' with the right length.
skip_dx = x2 - x1
skip_dy = y2 - y1
length = Sqr(skip_dx * skip_dx + skip_dy * skip_dy)
dash_dx = skip_dx / length * dash_length
dash_dy = skip_dy / length * dash_length
skip_dx = skip_dx / length * skip_length
skip_dy = skip_dy / length * skip_length

obj.DrawWidth = draw_width
X = x1
Y = y1
i_max = Int(length / (dash_length + skip_length))
For i = 1 To i_max
obj.Line (X, Y)-Step(dash_dx, dash_dy)
X = X + dash_dx + skip_dx
Y = Y + dash_dy + skip_dy
Next i

' See how much line is undrawn.
length = length - i_max * (dash_length + skip_length)
If length > dash_length Then
obj.Line (X, Y)-Step(dash_dx, dash_dy)
Else
obj.Line (X, Y)-(x2, y2)
End If
End Sub```