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
|
' sur la sub précédente
' (la variable Br_str() contient la date en string) :
'-----------------------
Dim e As PaintEventArgs
Dim pb As PictureBox = Me.PictureBox1
For i = 0 To 6
If i = 0 Then pb = Me.PictureBox1
If i = 1 Then pb = Me.PictureBox2
If i = 2 Then pb = Me.PictureBox3
If i = 3 Then pb = Me.PictureBox4
If i = 4 Then pb = Me.PictureBox5
If i = 5 Then pb = Me.PictureBox6
If i = 6 Then pb = Me.PictureBox7
If i = 0 Then
Moment = CDate(Br_Str(i))
dheur = Moment.Hour
dmin = Moment.Minute
OnPaint(e, pb, dheur, dmin)
End If
Next
'--------------------------------------
Protected Overloads Sub OnPaint(ByVal e As PaintEventArgs, ByVal pb As PictureBox, ByVal dheur As Integer, ByVal dmin As Integer)
Dim penBlack As New Pen(Color.Black, 1)
Dim a, b, c, x0, y0, x1, y1, x2, y2, x3, y3 As Single
Dim pointsDeLAiguille(3) As PointF
Dim brushBlack As New SolidBrush(Color.Black)
Dim brushAqua As New SolidBrush(Color.Aqua)
' Aiguille des Minutes
a = dmin * 200 / 60
b = a / 100 * 3.14159F
c = (a + 50) / 100 * 3.14159F
x0 = CSng(Math.Sin(b)) * 50
y0 = CSng(-Math.Cos(b)) * 50
x1 = CSng(-Math.Sin(b)) * 10
y1 = CSng(Math.Cos(b)) * 10
x2 = CSng(Math.Sin(c)) * 4
y2 = CSng(-Math.Cos(c)) * 4
x3 = CSng(-Math.Sin(c)) * 4
y3 = CSng(Math.Cos(c)) * 4
pointsDeLAiguille(0).X = x1 + 60
pointsDeLAiguille(0).Y = y1 + 60
pointsDeLAiguille(1).X = x2 + 60
pointsDeLAiguille(1).Y = y2 + 60
pointsDeLAiguille(2).X = x0 + 60
pointsDeLAiguille(2).Y = y0 + 60
pointsDeLAiguille(3).X = x3 + 60
pointsDeLAiguille(3).Y = y3 + 60
' c'est à la ligne ci-dessous que j'ai la classique erreur
' La référence d'objet n'est pas définie à une instance
' d'un objet
e.Graphics.FillPolygon(brushAqua, pointsDeLAiguille)
e.Graphics.DrawPolygon(penBlack, pointsDeLAiguille)
brushAqua.Dispose()
'-----------------------
' Aiguille des Heures
a = dheur * 200 / 12 + dmin * 200 / 60 / 12
b = a / 100 * 3.14159F
c = (a + 50) / 100 * 3.14159F
x0 = CSng(Math.Sin(b)) * 35
y0 = CSng(-Math.Cos(b)) * 35
x1 = CSng(-Math.Sin(b)) * 10
y1 = CSng(Math.Cos(b)) * 10
x2 = CSng(Math.Sin(c)) * 4
y2 = CSng(-Math.Cos(c)) * 4
x3 = CSng(-Math.Sin(c)) * 4
y3 = CSng(Math.Cos(c)) * 4
pointsDeLAiguille(0).X = x1 + 60
pointsDeLAiguille(0).Y = y1 + 60
pointsDeLAiguille(1).X = x2 + 60
pointsDeLAiguille(1).Y = y2 + 60
pointsDeLAiguille(2).X = x0 + 60
pointsDeLAiguille(2).Y = y0 + 60
pointsDeLAiguille(3).X = x3 + 60
pointsDeLAiguille(3).Y = y3 + 60
e.Graphics.FillPolygon(brushBlack, pointsDeLAiguille)
e.Graphics.DrawPolygon(penBlack, pointsDeLAiguille)
brushBlack.Dispose()
penBlack.Dispose()
End Sub |
Partager