Reputation: 649
I've made a class called BorderControl that inherits Control and is supposed to draw dashed borders. Before I go any further, this is the result:
Here is the abridged OnPaint method:
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Dim Height As Integer = ClientSize.Height
Dim Width As Integer = ClientSize.Width
With e.Graphics
Using HB As New HatchBrush(HatchStyle.DashedVertical, Color.Green, Color.Red)
Using P As New Pen(HB)
.DrawLine(P, Point.Empty, New Point(0, Height - 1))
.DrawLine(P, Point.Empty, New Point(Width - 1, 0))
.DrawLine(P, New Point(Width - 1, 0), New Point(Width - 1, Height - 1))
.DrawLine(P, New Point(0, Height - 1), New Point(Width - 1, Height - 1))
End Using
End Using
End With
End Sub
The only difference between this and the real method is that a Boolean value decides whether to draw dashed borders or solid borders.
Any ideas?
EDIT Before you point out the obvious, the actual method also uses HatchStyle.DashedHorizontal for the top and bottom lines, so that's not the problem.
Upvotes: 1
Views: 372
Reputation: 16991
HatchStyle.DashedVertical
looks like it only has pixels every 4 units. Fills like this are anchored against the top-left of the window they are drawn in (not the position the line was started from), meaning that if you try to draw a line that is on a pixel not evenly divisible by 4, you will only get the background color.
What you need is a fill that has foreground pixels in all columns and rows that will look dashed no matter how you "slice" it. I would recommend HatchStyle.LargeCheckerBoard
since it looks to me like it would produce the output that most closely matches your example, though other patterns may work.
Here is an image showing a preview of what every member of HatchStyle
looks like.
Upvotes: 3