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
| Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
Dim Rect As New Rectangle(0, 0, Me.Width - 1, Me.Height - 1)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.FillEllipse(New SolidBrush(Color.FromArgb(232, 220, 68)), New Rectangle(Rect.X + 1, Rect.Y + 1, Rect.Width - 3, Rect.Height - 3))
DrawHandHeure(g, Rect, _Heure)
g.FillEllipse(Brushes.Black, CInt(Rect.Width / 2.15), CInt(Rect.Height / 2.15), CInt(Rect.Width / 16), CInt(Rect.Height / 16))
End Sub
Private Sub DrawHandHeure(g As Graphics, r As Rectangle, hourAngle As Integer)
Dim center As New Point(r.Width / 2, r.Width / 2)
Dim _hourhand As Integer = CInt(center.X * 0.65)
Using Pen As New Pen(Color.Blue, 20)
Pen.EndCap = Drawing2D.LineCap.ArrowAnchor
g.DrawLine(Pen, center.X, center.Y, center.X + CInt(Math.Sin(hourAngle) * _hourhand), center.Y - CInt(Math.Cos(hourAngle) * _hourhand))
End Using
End Sub
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
MyBase.OnMouseDown(e)
isRotating = True
End Sub
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
MyBase.OnMouseMove(e)
If isRotating AndAlso e.Button = Windows.Forms.MouseButtons.Left Then
_Heure = 'rotation plus 30 degrée a chaque deplacement de la souris exemple : 1 à 12
End If
End Sub
Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
MyBase.OnMouseUp(e)
isRotating = False
End Sub |
Partager