Coding Nya:
Imports System.Math
Public Class Form1
Inherits System.Windows.Forms.Form
Dim l As Label
Const HaftSize = 150
Const SecondLength = 100
Const MinuteLength = 80
Const HourLength = 60
Dim Pen As New Drawing.Pen(System.Drawing.Color.Red, 2)
Dim Second, Minute, Hour As Integer
Dim x1, y1, x2, y2 As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Refresh() ' Clears Hands
Second = Microsoft.VisualBasic.DateAndTime.Second(Now)
Minute = Microsoft.VisualBasic.DateAndTime.Minute(Now)
Hour = Microsoft.VisualBasic.DateAndTime.Hour(Now)
' Draws Hour-Hand:
Pen = New Drawing.Pen(System.Drawing.Color.Red, 6)
x1 = Sin(((Hour Mod 12) * 30 + Minute / 2) * PI / 180 + PI) * HourLength / 5 + HaftSize 'Tail x
y1 = Cos(((Hour Mod 12) * 30 + Minute / 2) * PI / 180) * HourLength / 5 + HaftSize 'Tail y
x2 = Sin(((Hour Mod 12) * 30 + Minute / 2) * PI / 180) * HourLength + HaftSize 'Head x
y2 = Cos(((Hour Mod 12) * 30 + Minute / 2) * PI / 180 + PI) * HourLength + HaftSize 'Head y
Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)
' Draws Minute-Hand:
Pen = New Drawing.Pen(System.Drawing.Color.Red, 4)
x1 = Sin(Minute * PI / 30 + Second * PI / 1800 + PI) * MinuteLength / 5 + HaftSize
y1 = Cos(Minute * PI / 30 + Second * PI / 1800) * MinuteLength / 5 + HaftSize
x2 = Sin(Minute * PI / 30 + Second * PI / 1800) * MinuteLength + HaftSize
y2 = Cos(Minute * PI / 30 + Second * PI / 1800 + PI) * MinuteLength + HaftSize
Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)
' Draws Second-Hand:
Pen = New Drawing.Pen(System.Drawing.Color.Orange, 2)
x1 = Sin(Second * PI / 30 + PI) * SecondLength / 5 + HaftSize
y1 = Cos(Second * PI / 30) * SecondLength / 5 + HaftSize
x2 = Sin(Second * PI / 30) * SecondLength + HaftSize
y2 = Cos(Second * PI / 30 + PI) * SecondLength + HaftSize
Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Angle As Double
Dim i As Integer
Height = HaftSize * 2
Width = HaftSize * 2
'Draws and locates Digits:
For i = 0 To 11
Angle = i * PI / 6
x1 = Sin(Angle) * (SecondLength + 20) + HaftSize
y1 = Cos(Angle + PI) * (SecondLength + 20) + HaftSize
l = CallByName(Me, "lblDigit" & i, CallType.Get)
l.Left = x1 - l.Width / 2
l.Top = y1 - l.Height / 2
Next
End Sub
End Class
Hasilnya Seperti ini :
Tidak ada komentar:
Posting Komentar