Sei sulla pagina 1di 2
r a T n s F B B f A Y D . o Y
r
a
T
n
s
F
B
B
f
A
Y
D
.
o
Y
w
r
.
P
c
w
m
o
Y
w
Click here to buy
e
m
Y
r
B
2
.
B
0
A

analog

r o m f s e w w w n r . A a 2
r
o
m
f
s
e
w
w
w
n
r
.
A
a
2
r
B
.
T
B
0
Y
F
Y
D
.
P
c
o
Y
Click here to buy
m
Y
B
B
A

Jam analog denagn VB.NET Posted on September 16, 2007 by rawza

*** 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

Page 1

r a T n s F B B f A Y D . o Y
r
a
T
n
s
F
B
B
f
A
Y
D
.
o
Y
w
r
.
P
c
w
m
o
Y
w
Click here to buy
e
m
Y
r
B
2
.
B
0
A
r o m f s e w w w n r . A a 2
r
o
m
f
s
e
w
w
w
n
r
.
A
a
2
r
B
.
T
B
0
Y
F
Y
D
.
P
c
o
Y
Click here to buy
m
Y
B
B
A

analog 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

Page 2