Jam Analog
Imports System.Math
Public Class Form1
Dim l As Label
Const sete = 150
Const panjangDetik = 100
Const panjangMenit = 80
Const panjangJam = 60
Dim Pen As New Drawing.Pen(System.Drawing.Color.Red, 2)
Dim detik, menit, jam 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()
detik = Microsoft.VisualBasic.DateAndTime.Second(Now)
menit = Microsoft.VisualBasic.DateAndTime.Minute(Now)
jam = Microsoft.VisualBasic.DateAndTime.Hour(Now)
Pen = New Drawing.Pen(System.Drawing.Color.RoyalBlue, 6)
x1 = Sin(((jam Mod 12) * 30 + menit / 2) * PI / 180 + PI) * panjangJam / 5 + sete 'Tail x
y1 = Cos(((jam Mod 12) * 30 + menit / 2) * PI / 180) * panjangJam / 5 + sete 'Tail y
x2 = Sin(((jam Mod 12) * 30 + menit / 2) * PI / 180) * panjangJam + sete 'Head x
y2 = Cos(((jam Mod 12) * 30 + menit / 2) * PI / 180 + PI) * panjangJam + sete 'Head y
Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)
Pen = New Drawing.Pen(System.Drawing.Color.Purple, 4)
x1 = Sin(menit * PI / 30 + detik * PI / 1800 + PI) * panjangMenit / 5 + sete
y1 = Cos(menit * PI / 30 + detik * PI / 1800) * panjangMenit / 5 + sete
x2 = Sin(menit * PI / 30 + detik * PI / 1800) * panjangMenit + sete
y2 = Cos(menit * PI / 30 + detik * PI / 1800 + PI) * panjangMenit + sete
Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)
Pen = New Drawing.Pen(System.Drawing.Color.Orange, 2)
x1 = Sin(detik * PI / 30 + PI) * panjangDetik / 5 + sete
y1 = Cos(detik * PI / 30) * panjangDetik / 5 + sete
x2 = Sin(detik * PI / 30) * panjangDetik + sete
y2 = Cos(detik * PI / 30 + PI) * panjangDetik + sete
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 = sete * 2.3
Width = sete * 2
For i = 0 To 11
Angle = i * PI / 6
x1 = Sin(Angle) * (panjangDetik + 20) + sete
y1 = Cos(Angle + PI) * (panjangDetik + 20) + sete
l = CallByName(Me, "lblDigit" & i, CallType.Get)
l.Left = x1 - l.Width / 2
l.Top = y1 - l.Height / 2
Next
End Sub
End Class
Jam Digital
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim jamku As Date
jamku = DateTime.Now
Label2.Text = jamku.Hour.ToString()
Label1.Text = jamku.Minute.ToString()
Label3.Text = jamku.Second.ToString()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
End Class