|
Option Explicit On
Option Strict On
Imports System.Drawing.Drawing2D
Public Class Form1
Private myCylinder As New GraphicsPath
Private myCap As New GraphicsPath
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.CreatePath()
End Sub
Private Sub CreatePath()
Dim width As Integer = 200
Dim height As Integer = 80
Dim capWidth As Integer = 10
Me.myCylinder.AddRectangle(New Rectangle(CInt(width / 2 * -1), _
CInt(height / 2 * -1), width, height))
Me.myCylinder.AddEllipse(New Rectangle( _
CInt(width / 2 * -1 - capWidth / 2), _
CInt(height / 2 * -1), _
capWidth, height))
Me.myCylinder.FillMode = Drawing2D.FillMode.Winding
Me.myCap.AddEllipse(New Rectangle(CInt(width / 2 - capWidth / 2), _
CInt(height / 2 * -1), capWidth, height))
End Sub
Private Sub Transform()
Using m As New Matrix
m.Rotate(270, MatrixOrder.Append)
m.Scale(1, 1, MatrixOrder.Append)
m.Translate(200, 200, MatrixOrder.Append)
Me.myCylinder.Transform(m)
Me.myCap.Transform(m)
End Using
End Sub
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Using p As New Pen(Color.Black, 3)
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Me.Transform()
e.Graphics.DrawPath(p, Me.myCylinder)
e.Graphics.FillPath(Brushes.DarkGray, Me.myCylinder)
e.Graphics.DrawPath(p, Me.myCap)
e.Graphics.FillPath(Brushes.Gray, Me.myCap)
End Using
End Sub
End Class |