1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
Imports System.Drawing.Drawing2D
Public Class UserControl1
Private Sub UserControl1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
btnDrawLines.Text = "drawlines"
btnPathDrawLines.Text = "pathdrawlines"
End Sub
Private Sub btnDrawLines_Click(sender As System.Object, e As System.EventArgs) Handles btnDrawLines.Click
Using gr As Graphics = Me.CreateGraphics()
gr.Clear(Me.BackColor)
DrawLines(gr)
End Using
End Sub
Private Sub btnPathDrawLines_Click(sender As System.Object, e As System.EventArgs) Handles btnPathDrawLines.Click
Using gr As Graphics = Me.CreateGraphics()
gr.Clear(Me.BackColor)
PathDrawLines(gr)
End Using
End Sub
Private Sub DrawLines(gr As Graphics)
Dim red As New Pen(Brushes.Red, 2.0)
Dim blue As New Pen(Brushes.Blue, 3.0)
Dim brown As New Pen(Brushes.Brown, 3.0)
Dim magenta As New Pen(Brushes.Magenta, 3.0)
Dim offset As Integer = 20
Dim angle As Double = Math.PI / 4
Dim rect As New Rectangle(100, 50, 100, 200)
Dim points() As Point
'cote haut
Dim p0 As New Point(rect.Left, rect.Top)
Dim p1 As Point = New Point(rect.Right, rect.Top)
'cote droit
Dim p2 As New Point(rect.Right + offset, rect.Top + offset)
Dim p3 As New Point(rect.Right + offset, rect.Top + offset + rect.Height)
'cote bas
Dim p4 As New Point(rect.Right, rect.Bottom + 2 * offset)
Dim p5 As New Point(rect.Left, rect.Bottom + 2 * offset)
'cote gauche
Dim p6 As New Point(rect.Left - offset, rect.Top + offset + rect.Height)
Dim p7 As New Point(rect.Left - offset, rect.Top + offset)
gr.DrawLine(red, p0, p1)
points = GetDiagonal(p0, 3 * angle, offset)
gr.DrawLines(red, points)
points = GetDiagonal(p1, angle, offset)
gr.DrawLines(red, points)
gr.DrawLine(blue, p2, p3)
points = GetDiagonal(p2, -3 * angle, offset)
gr.DrawLines(blue, points)
points = GetDiagonal(p3, 3 * angle, offset)
gr.DrawLines(blue, points)
gr.DrawLine(brown, p4, p5)
points = GetDiagonal(p4, -angle, offset)
gr.DrawLines(brown, points)
points = GetDiagonal(p5, -3 * angle, offset)
gr.DrawLines(brown, points)
gr.DrawLine(magenta, p6, p7)
points = GetDiagonal(p6, angle, offset)
gr.DrawLines(magenta, points)
points = GetDiagonal(p7, -angle, offset)
gr.DrawLines(magenta, points)
End Sub
Private Sub PathDrawLines(gr As Graphics)
Dim brRed As New SolidBrush(Color.Red)
Dim brBlue As New SolidBrush(Color.BlueViolet)
Dim brBrown As New SolidBrush(Color.Brown)
Dim brMagenta As New SolidBrush(Color.Magenta)
Dim widenPen As New Pen(Brushes.Aquamarine, 10.0)
Dim widenBrush As New SolidBrush(Color.Turquoise)
Dim offset As Integer = 20
Dim angle As Double = Math.PI / 4
Dim rect As New Rectangle(100, 50, 100, 200)
Dim points As New List(Of Point)
'cote haut
Dim p0 As New Point(rect.Left, rect.Top)
Dim p1 As Point = New Point(rect.Right, rect.Top)
'cote droit
Dim p2 As New Point(rect.Right + offset, rect.Top + offset)
Dim p3 As New Point(rect.Right + offset, rect.Top + offset + rect.Height)
'cote bas
Dim p4 As New Point(rect.Right, rect.Bottom + 2 * offset)
Dim p5 As New Point(rect.Left, rect.Bottom + 2 * offset)
'cote gauche
Dim p6 As New Point(rect.Left - offset, rect.Top + offset + rect.Height)
Dim p7 As New Point(rect.Left - offset, rect.Top + offset)
Dim pth As New GraphicsPath
points.AddRange(GetDiagonal(p0, 3 * angle, offset))
points.AddRange(New Point() {p0, p1})
points.AddRange(GetDiagonal(p1, angle, offset))
pth.AddLines(points.ToArray)
pth.Widen(widenPen)
gr.FillPath(brRed, pth)
pth.Reset()
points.Clear()
points.AddRange(GetDiagonal(p2, -3 * angle, offset))
points.AddRange(New Point() {p2, p3})
points.AddRange(GetDiagonal(p3, 3 * angle, offset))
pth.AddLines(points.ToArray)
pth.Widen(widenPen)
gr.FillPath(brBlue, pth)
pth.Reset()
points.Clear()
points.AddRange(GetDiagonal(p4, -angle, offset))
points.AddRange(New Point() {p4, p5})
points.AddRange(GetDiagonal(p5, -3 * angle, offset))
pth.AddLines(points.ToArray)
pth.Widen(widenPen)
gr.FillPath(brBrown, pth)
pth.Reset()
points.Clear()
points.AddRange(GetDiagonal(p6, angle, offset))
points.AddRange(New Point() {p6, p7})
points.AddRange(GetDiagonal(p7, -angle, offset))
pth.AddLines(points.ToArray)
pth.Widen(widenPen)
gr.FillPath(brMagenta, pth)
pth.Dispose()
End Sub
'FONCTION DIAGONALE
Private Function GetDiagonal(startPoint As Point, angle As Double, offset As Integer) As Point()
Dim length As Double = offset * Math.Sqrt(2) / 2
Dim x As Double = startPoint.X + (Math.Cos(angle) * length)
Dim y As Double = startPoint.Y + (Math.Sin(angle) * length)
Dim endPoint As New Point(Convert.ToInt32(x), Convert.ToInt32(y))
Dim pts() As Point = New Point() {startPoint, endPoint}
Return pts
End Function
End Class |
Partager