我创建了一个名为BorderControl的类,它继承了Control,并且应该绘制虚线边框。在进一步讨论之前,结果如下:
这是简化的OnPaint方法:
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
此方法与实际方法的唯一区别在于布尔值决定是绘制虚线边框还是实心边框。
有什么想法吗?
修改 在你指出显而易见的事实之前,实际的方法也使用HatchStyle.DashedHorizontal作为顶行和底行,所以这不是问题。