绘制形状
要开始绘制形状,你需要定义一个笔对象 Pen
接受两个参数:
- 笔颜色或画笔
- 笔宽
笔对象用于创建要绘制的对象的轮廓
定义笔后,你可以设置特定的笔属性
Dim pens As New Pen(Color.Purple)
pens.DashStyle = DashStyle.Dash 'pen will draw with a dashed line
pens.EndCap = LineCap.ArrowAnchor 'the line will end in an arrow
pens.StartCap = LineCap.Round 'The line draw will start rounded
'*Notice* - the Start and End Caps will not show if you draw a closed shape
然后使用你创建的图形对象绘制形状
Private Sub GraphicForm_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim pen As New Pen(Color.Blue, 15) 'Use a blue pen with a width of 15
Dim point1 As New Point(5, 15) 'starting point of the line
Dim point2 As New Point(30, 100) 'ending point of the line
e.Graphics.DrawLine(pen, point1, point2)
e.Graphics.DrawRectangle(pen, 60, 90, 200, 300) 'draw an outline of the rectangle
默认情况下,笔的宽度等于 1
Dim pen2 as New Pen(Color.Orange) 'Use an orange pen with width of 1
Dim origRect As New Rectangle(90, 30, 50, 60) 'Define bounds of arc
e.Graphics.DrawArc(pen2, origRect, 20, 180) 'Draw arc in the rectangle bounds
End Sub