Jam analog denagn VB.NET

*** langsung copy pastekan code ini dan jgn lupa di compile….

Imports System.Math
Imports Microsoft.VisualBasic
Public Class Form1
Inherits System.Windows.Forms.Form

#Region ” Windows Form Designer generated code ”

‘objek pen
Dim l As Label
Const ukrtengah = 150
Const jrmdetik = 100
Const jrmmenit = 80
Const jrmjam = 60
Dim pen As New Drawing.Pen(Color.Red, 2)
Dim detik, menit, jam As Integer
Dim x1, x2, y1, y2 As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1000
Dim sudut As Double
Dim i As Integer
For i = 1 To 12
sudut = i * PI / 6
x1 = Sin(sudut) * (jrmdetik + 20) + ukrtengah
y1 = Cos(sudut + PI) * (jrmdetik + 20) + ukrtengah
l = CallByName(Me, “label” & i, CallType.Get)
l.Left = x1 – l.Width / 2
l.Top = y1 – l.Height / 2
Next
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim g As Graphics = Me.CreateGraphics
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Refresh()
detik = DateAndTime.Second(Now)
menit = DateAndTime.Minute(Now)
jam = DateAndTime.Hour(Now)
‘—————————
pen = New Drawing.Pen(Color.Red, 6)
x1 = Sin(((jam Mod 12) * 30 + menit / 2) * PI / 180 + PI) * jrmjam / 5 + ukrtengah
y1 = Cos(((jam Mod 12) * 30 + menit / 2) * PI / 180) * jrmjam / 5 + ukrtengah
x2 = Sin(((jam Mod 12) * 30 + menit / 2) * PI / 180) * jrmjam + ukrtengah
y2 = Cos(((jam Mod 12) * 30 + menit / 2) * PI / 180 + PI) * jrmjam + ukrtengah
g.DrawLine(pen, x1, y1, x2, y2)
‘—————————
pen = New Drawing.Pen(Color.Red, 4)
x1 = Sin(menit * PI / 30 + detik * PI / 1800 + PI) * jrmmenit / 5 + ukrtengah
y1 = Cos(menit * PI / 30 + detik * PI / 1800) * jrmmenit / 5 + ukrtengah
x2 = Sin(menit * PI / 30 + detik * PI / 1800) * jrmmenit + ukrtengah
y2 = Cos(menit * PI / 30 + detik * PI / 1800 + PI) * jrmmenit + ukrtengah
g.DrawLine(pen, x1, y1, x2, y2)
‘————————–
pen = New Drawing.Pen(Color.Red, 2)
x1 = Sin(detik * PI / 30 + PI) * jrmdetik / 5 + ukrtengah
y1 = Cos(detik * PI / 30) * jrmdetik / 5 + ukrtengah
x2 = Sin(detik * PI / 30) * jrmdetik + ukrtengah
y2 = Cos(detik * PI / 30 + PI) * jrmdetik + ukrtengah
g.DrawLine(pen, x1, y1, x2, y2)
End Sub
Protected Overrides Sub onpaint(ByVal e As PaintEventArgs)
Dim gr As Graphics
gr = e.Graphics
gr.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim pe As New Pen(Color.Blue, 3)
gr.DrawEllipse(pe, 0, 5, 290, 290)
End Sub
End Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: